From patchwork Tue Sep 24 11:23:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15252 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 11071449561 for ; Tue, 24 Sep 2019 14:24:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E975E689D90; Tue, 24 Sep 2019 14:24:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 20EE96881C5 for ; Tue, 24 Sep 2019 14:24:17 +0300 (EEST) Received: by mail-pl1-f174.google.com with SMTP id u20so879292plq.4 for ; Tue, 24 Sep 2019 04:24:17 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=EymT+0NeRuIxi1nmKEzg8L3t5Hvmj9EkfMzzXPlNJLo=; b=f1mPL5WFkHb75O3TiJ0lza1/DXZ0V03D0X5te4TdPzu8stw/nj1ywMiGeT5EEmJStf xind8X1hCkRuZTxI2lH85OrVQiI6DL1NkWaKi4Dphf84FSHDoQCNrds7vbMzYdEveXup LDe8JJtxyEx6CTMXCOl54Lq5QxuQsMFy5Iqt4wxkjXftOWSacACqu3ph6ycjLQ1BgVV+ NpYVrUUmLzEPFEqCvTxXbJIMr9iCkaT/Vvth6t0Hzz/oFLRed9zWlEBM3KXGTvHjJMn2 F0LsHXZvtN3lIsKzaa4zR0X5nhqKVIs9Ev0fkjXB7sktPIqqioSD3BD3U0gwH5Lzhsay PTNg== 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:mime-version:content-transfer-encoding; bh=EymT+0NeRuIxi1nmKEzg8L3t5Hvmj9EkfMzzXPlNJLo=; b=XOp+0gwD6mOXdC1zjm4Crkkuc9JUZiJ2tN5UWjr4TRlRxMtk8o1+Cp5TsYKL/OEr5E TuJptf1sYyobZhFdwq2vUVNe91NZAF8z44///fsX3jE0R5HJa1KhWEC58+fQZv/LEGbh LnWgT3nWzSVbY9noqZP0EMlBS9QCn8XOLbREEgBX7w1nnEk8fYUxImhwED1fC5YtTDy1 NvaHg8A4rA7qD7O8V+dzB8GeRFKiityEg5qGd6tdpWZf+CM9/sPRWE3RrWqFREG67CT0 3AnJM2j/lwKaNkknsx7Ui/t5zme6RoDfARhit5vwSZ08PA6IXToElrjtSKakyBl2IY9+ abuw== X-Gm-Message-State: APjAAAXip6k+1IOY+AD1wADDFgEftCUpqpVQxKT3hp6j77bLqGYH7o4t Q3GTevDuBOmW7L/uli6k1ImCUlOl X-Google-Smtp-Source: APXvYqyNCGGxusoTGqoEmAQVRbHJjA6Po2xfyjtITtHTzM/8lhAUWhLz5LA0cyfy548MsGdYvZbcIw== X-Received: by 2002:a17:902:b288:: with SMTP id u8mr2384875plr.127.1569324255101; Tue, 24 Sep 2019 04:24:15 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id y7sm1887217pfn.142.2019.09.24.04.24.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Sep 2019 04:24:14 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 24 Sep 2019 19:23:58 +0800 Message-Id: <20190924112401.14020-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <1568595818-7943-1-git-send-email-lance.lmwang@gmail.com> References: <1568595818-7943-1-git-send-email-lance.lmwang@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/4] avutil/avstring: support input path as a null pointer or empty string 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Linux and OSX systems support basename and dirname via , I plan to make the wrapper interface conform to the standard interface first. If it is feasible, I will continue to modify it to call the system interface if there is already a system call interface. You can get more description about the system interface by below command: "man 3 basename" Reviewed-by: Marton Balint Reviewed-by: Tomas Härdin Reviewed-by: Liu Steven Signed-off-by: Limin Wang --- libavutil/avstring.c | 12 ++++++++---- libavutil/avstring.h | 13 +++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 4c068f5bc5..76a13ba3b5 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -257,8 +257,12 @@ char *av_strireplace(const char *str, const char *from, const char *to) const char *av_basename(const char *path) { - char *p = strrchr(path, '/'); + char *p; + if (!path || *path == '\0') + return "."; + + p = strrchr(path, '/'); #if HAVE_DOS_PATHS char *q = strrchr(path, '\\'); char *d = strchr(path, ':'); @@ -274,11 +278,11 @@ const char *av_basename(const char *path) const char *av_dirname(char *path) { - char *p = strrchr(path, '/'); + char *p = path ? strrchr(path, '/') : NULL; #if HAVE_DOS_PATHS - char *q = strrchr(path, '\\'); - char *d = strchr(path, ':'); + char *q = path ? strrchr(path, '\\') : NULL; + char *d = path ? strchr(path, ':') : NULL; d = d ? d + 1 : d; diff --git a/libavutil/avstring.h b/libavutil/avstring.h index 37dd4e2da0..274335cfb9 100644 --- a/libavutil/avstring.h +++ b/libavutil/avstring.h @@ -274,16 +274,21 @@ char *av_strireplace(const char *str, const char *from, const char *to); /** * Thread safe basename. - * @param path the path, on DOS both \ and / are considered separators. + * @param path the string to parse, on DOS both \ and / are considered separators. * @return pointer to the basename substring. + * If path does not contain a slash, the function returns a copy of path. + * If path is a NULL pointer or points to an empty string, a pointer + * to a string "." is returned. */ const char *av_basename(const char *path); /** * Thread safe dirname. - * @param path the path, on DOS both \ and / are considered separators. - * @return the path with the separator replaced by the string terminator or ".". - * @note the function may change the input string. + * @param path the string to parse, on DOS both \ and / are considered separators. + * @return A pointer to a string that's the parent directory of path. + * If path is a NULL pointer or points to an empty string, a pointer + * to a string "." is returned. + * @note the function may modify the contents of the path, so copies should be passed. */ const char *av_dirname(char *path);