From patchwork Mon Dec 2 04:51:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 16520 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 57821449BC5 for ; Mon, 2 Dec 2019 06:51:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F03868AF91; Mon, 2 Dec 2019 06:51:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA6CB68AF88 for ; Mon, 2 Dec 2019 06:51:15 +0200 (EET) Received: by mail-pl1-f194.google.com with SMTP id q16so11505342plr.10 for ; Sun, 01 Dec 2019 20:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=80cmhy6iAIZrBxyUKPC09tLh7j2Qs+xLAuqe1JqabWM=; b=a1Pq+xpHLBTg9FK+hY0janEEEijT7YWXRuvoD9EKOO6VFlmReyo6aqzL9vWyk1vxe/ HhkNcyRJ2l3VcH6S8ARvOquWmyu3Up0CiSBOA5jEvha3x7JzDhpxgNa8l/f5X0CoIp53 y9HDP3xeIrdjAZSrEJPfg0xbEBOQuA90eYodjxSh83huRt8U4XjH2nYRyVqaX1jDR9y/ toTKzzixkLHZYAgEEXJ4EHNidGb5bw7F4Sqs1PM1Y8ddyyLuBW4VWkD08AgpzWfu+rXz NvhXZ//dZMl4zpU+2hvIz0oCyJgGNntaUUwjQ9ffH0gS9bKNk8TsCxqJzQ2B2XupY/eu Oinw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=80cmhy6iAIZrBxyUKPC09tLh7j2Qs+xLAuqe1JqabWM=; b=JN6rNRFYnz+mKHexDTBZgloL0KHcNjMox5c+abuLjHF+8KsmMbbJi2aY4shv0WyYE/ ZJGm1LlOrdcqhRGsLzLUDnjy6QEFkNvGkJSPgeHyUTB5k7YajKoZ5dztxcCioRO56zSD gpwwc1rY8VepAzTX6Zhp2mJFl51+N9/y/NiOHTP38xQ1/bOsZe46tELKQGhLa/u6AXRk +KTqTuI8gtWYgxiFKqW6oje7xm/wlkbdMVHhtlCOBlxCkDHwUt+cdpOOf/XTfBSPcica TA+DDtfvBUn2UCTvxQY2e+/8T3/lN/DcikI7NnvH2nLdM3k41rQBTd+96eP4NflWFTLt zOQw== X-Gm-Message-State: APjAAAUi/MlsgfoDsVLE0+T4nWYGlVaem1veUKlIf9iBEVz5DEADEd+s 8pVMdtqzcm0QR8pepUbAm1U6uR7l X-Google-Smtp-Source: APXvYqwS/dXf0ipjMea+82rBQxKXWffIKdr30m3FGFVmhz/aYwjS785ilUiZexREvkgodoJQZirn6g== X-Received: by 2002:a17:902:8a97:: with SMTP id p23mr19195266plo.233.1575262274197; Sun, 01 Dec 2019 20:51:14 -0800 (PST) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id i13sm17807723pgr.48.2019.12.01.20.51.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Dec 2019 20:51:13 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Dec 2019 12:51:06 +0800 Message-Id: <20191202045106.27737-2-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20191202045106.27737-1-lance.lmwang@gmail.com> References: <20191201140042.26305-1-lance.lmwang@gmail.com> <20191202045106.27737-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v3 2/2] avformat/utils: simplify the ff_mkdir_p with SEPARATOR X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Please tested by below command(Mac or Linux): ./ffmpeg -i ~/Movies/input.mp4 -use_localtime 1 -use_localtime_mkdir 1 -hls_segment_filename 'hls/t\e\s\t/%Y%m%d/file-%Y%m%d-%s.ts' ./out.m3u8 Master: $ ls hls/ t t\e t\e\s t\e\s\t After applied the patch: $ ls hls/ t\e\s\t Signed-off-by: Limin Wang --- libavformat/utils.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 03a3705200..0a94515e0e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4843,32 +4843,36 @@ void av_url_split(char *proto, int proto_size, } } +#if HAVE_DOS_PATHS +#define SEPARATOR '\\' +#else +#define SEPARATOR '/' +#endif + int ff_mkdir_p(const char *path) { int ret = 0; char *temp = av_strdup(path); char *pos = temp; - char tmp_ch = '\0'; if (!path || !temp) { return -1; } - if (*temp == '/' || *temp == '\\') + if (*temp == SEPARATOR) pos++; - else if (*temp == '.' && (*(temp+1) == '/' || *(temp+1) == '\\')) + else if (*temp == '.' && *(temp+1) == SEPARATOR) pos += 2; for ( ; *pos != '\0'; ++pos) { - if (*pos == '/' || *pos == '\\') { - tmp_ch = *pos; + if (*pos == SEPARATOR) { *pos = '\0'; ret = mkdir(temp, 0755); - *pos = tmp_ch; + *pos = SEPARATOR; } } - if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) { + if (*(pos - 1) != SEPARATOR) { ret = mkdir(temp, 0755); }