2014-02-20 03:14:39 +08:00
|
|
|
/****************************************************************************
|
2021-03-09 05:39:04 +08:00
|
|
|
* fs/inode/fs_inodebasename.c
|
2014-02-20 03:14:39 +08:00
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-02-20 03:14:39 +08:00
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-02-20 03:14:39 +08:00
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-02-20 03:14:39 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-09-29 21:14:38 +08:00
|
|
|
#include "inode/inode.h"
|
2014-02-20 03:14:39 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-12-03 00:47:32 +08:00
|
|
|
* Name: inode_basename
|
2014-02-20 03:14:39 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2015-12-03 00:47:32 +08:00
|
|
|
* Given a path with node names separated by '/', return name of last
|
|
|
|
* segment in the path. ""
|
2014-02-20 03:14:39 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR const char *inode_basename(FAR const char *name)
|
|
|
|
{
|
|
|
|
FAR const char *basename = NULL;
|
|
|
|
|
2015-10-12 01:39:29 +08:00
|
|
|
for (; ; )
|
2014-02-20 03:14:39 +08:00
|
|
|
{
|
|
|
|
/* Get the name for the next path segment */
|
|
|
|
|
|
|
|
name = inode_nextname(name);
|
|
|
|
|
|
|
|
/* When the final segment is terminated by the NUL character, then
|
|
|
|
* previous name that we saved is the basename.
|
|
|
|
*/
|
|
|
|
|
2015-12-03 00:47:32 +08:00
|
|
|
if (name == NULL || *name == '\0')
|
2014-02-20 03:14:39 +08:00
|
|
|
{
|
2015-12-03 00:47:32 +08:00
|
|
|
/* Break out of the loop with basename pointer to the final
|
|
|
|
* segment of the path.
|
|
|
|
*/
|
|
|
|
|
|
|
|
break;
|
2014-02-20 03:14:39 +08:00
|
|
|
}
|
|
|
|
|
2015-12-03 00:47:32 +08:00
|
|
|
/* Set basename to point to the remainder of the path */
|
|
|
|
|
|
|
|
basename = name;
|
|
|
|
}
|
2014-02-20 03:14:39 +08:00
|
|
|
|
2015-12-03 00:47:32 +08:00
|
|
|
return basename;
|
2014-02-20 03:14:39 +08:00
|
|
|
}
|