1 /****************************************************************************
2 * fs/dirent/fs_telldir.c
3 *
4 * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved.
5 * Based on NuttX originally written by Gregory Nutt
6 *
7 * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
8 * Author: Gregory Nutt <gnutt@nuttx.org>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * 3. Neither the name NuttX nor the names of its contributors may be
21 * used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
31 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ****************************************************************************/
38
39 /****************************************************************************
40 * Included Files
41 ****************************************************************************/
42 #include "vfs_config.h"
43
44 #include "sys/types.h"
45 #include "dirent.h"
46 #include "errno.h"
47
48 #include "fs/dirent_fs.h"
49
50
51 /****************************************************************************
52 * Public Functions
53 ****************************************************************************/
54
55 /****************************************************************************
56 * Name: telldir
57 *
58 * Description:
59 * The telldir() function returns the current location
60 * associated with the directory stream dirp.
61 *
62 * Inputs:
63 * dirp -- An instance of type DIR created by a previous
64 * call to opendir();
65 *
66 * Return:
67 * On success, the telldir() function returns the current
68 * location in the directory stream. On error, -1 is
69 * returned, and errno is set appropriately.
70 *
71 * EBADF - Invalid directory stream descriptor dir
72 *
73 ****************************************************************************/
74
telldir(DIR *dirp)75 long telldir(DIR *dirp)
76 {
77 struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
78
79 if (!idir || !idir->fd_root)
80 {
81 set_errno(EBADF);
82 return (off_t)-1;
83 }
84
85 /* Just return the current position */
86
87 return idir->fd_position;
88 }
89
90