From patchwork Fri Sep 20 02:53:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15169 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 02D734478B4 for ; Fri, 20 Sep 2019 05:53:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E04B0689A28; Fri, 20 Sep 2019 05:53:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B9F016899EA for ; Fri, 20 Sep 2019 05:53:47 +0300 (EEST) Received: by mail-pf1-f177.google.com with SMTP id q12so3525620pff.9 for ; Thu, 19 Sep 2019 19:53:47 -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=Pl/lHDtnoRjSj3n8buYJIFNV+z1+zRs0zWTcOaPYefg=; b=HXkwvvbmSg3eqioZBaq5ggrVg5Osey9r6hwhn2LfUAPCoLL/3VxTRgcT0A3jgLzHAC 6aiiYbZETCIK0OxVwpuhqsa8oCWFzBCcKGwOYkR29vQhHYeq0lyJaUVX6wK7t1fHWy6z hBrY8uTDxN4MtL7fdLmsYoPQu7CUGV/HDYJAZ/sKkaOs4DbpsKpy3iF+NYRadHC/9tcT pJ4I8IqbLU4tui5fSx0GheHqPO40zhYLTcT7/6uK4P737EtEN54E7By7lftPXRB4hBRP gyfdUJCmNc6oAdxOrKnZPMHEOdeiJNGHsaYT4vKDfxQegzdfKRP4EUL5zWA3gH7KKbyd XVIw== 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=Pl/lHDtnoRjSj3n8buYJIFNV+z1+zRs0zWTcOaPYefg=; b=BhH2mQMEPuzNorA4Tc0z9pwkVq2TAOARNOF0IZUgPsuwL/tKqaV6/fkvMoIdUTR6Ce xZ/POYhXRdteL5FsMkB2oU+qdKQv0fSDwCAnfdGEDOUbYS/JN5JwoHa61U013qkG+QvT mmi0k0IqyXXZKivEKvc86vi92gPmINi3cIeKZvARJMfFU9dgRlnXQjdAaHwCWHk381eB LGCK0iWY8V7IyaTfiU43tT/sNCPcym0b2Mcy7DTD31adga76XxS7ULGHgUnHtPpbEsUU goVWIiOTMkw/oykm4qxbmL4gPg8pLn0bqSVcwi6Ue/UZok+Bn8QscBaF8reetODDLLB4 7iSQ== X-Gm-Message-State: APjAAAWTPmBJ2HuVf+XGhTo8TVlDUYHAfbvMz9e0yDNbt35l32gLnpSr kAFW/iyP6dQXwIv566guaVWq7kgN X-Google-Smtp-Source: APXvYqxDEUP223ifjYJBDSqgEGX8gWQEKVXg6ysNioBei456SjZ8aLEonJXg5iUFgYOIPgcXIsgIKQ== X-Received: by 2002:a65:6901:: with SMTP id s1mr12393751pgq.338.1568948025545; Thu, 19 Sep 2019 19:53:45 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id l7sm286830pga.92.2019.09.19.19.53.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Sep 2019 19:53:44 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2019 10:53:38 +0800 Message-Id: <20190920025338.4436-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 v3] avutil/avstring: support input path is 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 descrioption 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 4c068f5..76a13ba 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 37dd4e2..274335c 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);