2014-02-19 20:14:39 +01:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* fs/inode/fs_inodebasename.c
|
2014-02-19 20:14:39 +01:00
|
|
|
*
|
2021-02-03 14:47:23 +01: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-19 20:14:39 +01:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-02-19 20:14:39 +01:00
|
|
|
*
|
2021-02-03 14:47:23 +01: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-19 20:14:39 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-09-29 15:14:38 +02:00
|
|
|
#include "inode/inode.h"
|
2014-02-19 20:14:39 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-12-02 17:47:32 +01:00
|
|
|
* Name: inode_basename
|
2014-02-19 20:14:39 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-12-02 17:47:32 +01:00
|
|
|
* Given a path with node names separated by '/', return name of last
|
|
|
|
* segment in the path. ""
|
2014-02-19 20:14:39 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR const char *inode_basename(FAR const char *name)
|
|
|
|
{
|
|
|
|
FAR const char *basename = NULL;
|
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
for (; ; )
|
2014-02-19 20:14:39 +01: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-02 17:47:32 +01:00
|
|
|
if (name == NULL || *name == '\0')
|
2014-02-19 20:14:39 +01:00
|
|
|
{
|
2015-12-02 17:47:32 +01:00
|
|
|
/* Break out of the loop with basename pointer to the final
|
|
|
|
* segment of the path.
|
|
|
|
*/
|
|
|
|
|
|
|
|
break;
|
2014-02-19 20:14:39 +01:00
|
|
|
}
|
|
|
|
|
2015-12-02 17:47:32 +01:00
|
|
|
/* Set basename to point to the remainder of the path */
|
|
|
|
|
|
|
|
basename = name;
|
|
|
|
}
|
2014-02-19 20:14:39 +01:00
|
|
|
|
2015-12-02 17:47:32 +01:00
|
|
|
return basename;
|
2014-02-19 20:14:39 +01:00
|
|
|
}
|