diff options
| author | [email protected] <[email protected]> | 2012-07-10 09:25:19 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-07-10 09:25:19 +0000 |
| commit | fdc7dfc768f8646b3a2c59c39c0ca2fc7c065f8d (patch) | |
| tree | fe2deb447653d9cad00ca0131c923fc3b76dffa3 /components/dfs | |
| parent | 9d4072ce5926c7a96bf38e92b8f679f34c593572 (diff) | |
use RT_NULL instead of NULL in DFS, and format the code in DFS
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2213 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/dfs')
| -rw-r--r-- | components/dfs/src/dfs.c | 93 | ||||
| -rw-r--r-- | components/dfs/src/dfs_posix.c | 51 |
2 files changed, 92 insertions, 52 deletions
diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 3db6e51694..05a7615f2e 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -1,7 +1,7 @@ /* * File : dfs.c * This file is part of Device File System in RT-Thread RTOS - * COPYRIGHT (C) 2004-2011, RT-Thread Development Team + * COPYRIGHT (C) 2004-2012, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -38,6 +38,7 @@ struct dfs_fd fd_table[DFS_FD_MAX]; /** * @addtogroup DFS */ + /*@{*/ /** @@ -204,6 +205,7 @@ int fd_is_open(const char *pathname) { /* can't find mounted file system */ rt_free(fullpath); + return -1; } @@ -225,6 +227,7 @@ int fd_is_open(const char *pathname) /* found file in file descriptor table */ rt_free(fullpath); dfs_unlock(); + return 0; } } @@ -256,6 +259,7 @@ const char *dfs_subdir(const char *directory, const char *filename) { dir --; } + return dir; } @@ -276,12 +280,13 @@ char *dfs_normalize_path(const char *directory, const char *filename) RT_ASSERT(filename != RT_NULL); #ifdef DFS_USING_WORKDIR - if (directory == NULL) /* shall use working directory */ + if (directory == RT_NULL) /* shall use working directory */ directory = &working_directory[0]; #else - if ((directory == NULL) && (filename[0] != '/')) + if ((directory == RT_NULL) && (filename[0] != '/')) { rt_kprintf(NO_WORKING_DIR); + return RT_NULL; } #endif @@ -307,61 +312,61 @@ char *dfs_normalize_path(const char *directory, const char *filename) { char c = *src; - if (c == '.') - { - if (!src[1]) src ++; /* '.' and ends */ - else if (src[1] == '/') - { - /* './' case */ - src += 2; + if (c == '.') + { + if (!src[1]) src ++; /* '.' and ends */ + else if (src[1] == '/') + { + /* './' case */ + src += 2; - while ((*src == '/') && (*src != '\0')) - src ++; - continue; - } - else if (src[1] == '.') - { - if (!src[2]) - { + while ((*src == '/') && (*src != '\0')) + src ++; + continue; + } + else if (src[1] == '.') + { + if (!src[2]) + { /* '..' and ends case */ - src += 2; - goto up_one; - } - else if (src[2] == '/') - { + src += 2; + goto up_one; + } + else if (src[2] == '/') + { /* '../' case */ - src += 3; + src += 3; - while ((*src == '/') && (*src != '\0')) - src ++; - goto up_one; - } - } - } + while ((*src == '/') && (*src != '\0')) + src ++; + goto up_one; + } + } + } - /* copy up the next '/' and erase all '/' */ - while ((c = *src++) != '\0' && c != '/') - *dst ++ = c; + /* copy up the next '/' and erase all '/' */ + while ((c = *src++) != '\0' && c != '/') + *dst ++ = c; - if (c == '/') - { - *dst ++ = '/'; - while (c == '/') - c = *src++; + if (c == '/') + { + *dst ++ = '/'; + while (c == '/') + c = *src++; - src --; - } - else if (!c) - break; + src --; + } + else if (!c) + break; - continue; + continue; up_one: dst --; if (dst < dst0) { rt_free(fullpath); - return NULL; + return RT_NULL; } while (dst0 < dst && dst[-1] != '/') dst --; diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index ea6ba19810..0ca0d31b4e 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -42,7 +42,7 @@ int open(const char *file, int flags, int mode) rt_set_errno(-DFS_STATUS_ENOMEM);
return -1;
}
- d = fd_get(fd);
+ d = fd_get(fd);
result = dfs_file_open(d, file, flags);
if (result < 0)
@@ -58,6 +58,7 @@ int open(const char *file, int flags, int mode) /* release the ref-count of fd */
fd_put(d);
+
return fd;
}
@@ -87,10 +88,12 @@ int close(int fd) if (result < 0)
{
rt_set_errno(result);
+
return -1;
}
fd_put(d);
+
return 0;
}
@@ -110,7 +113,7 @@ int read(int fd, void *buf, size_t len) struct dfs_fd *d;
/* get the fd */
- d = fd_get(fd);
+ d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
@@ -128,6 +131,7 @@ int read(int fd, void *buf, size_t len) /* release the ref-count of fd */
fd_put(d);
+
return result;
}
@@ -147,10 +151,11 @@ int write(int fd, const void *buf, size_t len) struct dfs_fd *d;
/* get the fd */
- d = fd_get(fd);
+ d = fd_get(fd);
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
+
return -1;
}
@@ -165,6 +170,7 @@ int write(int fd, const void *buf, size_t len) /* release the ref-count of fd */
fd_put(d);
+
return result;
}
@@ -206,12 +212,12 @@ off_t lseek(int fd, off_t offset, int whence) default:
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
-
}
if (offset < 0)
{
rt_set_errno(-DFS_STATUS_EINVAL);
+
return -1;
}
result = dfs_file_lseek(d, offset);
@@ -219,11 +225,13 @@ off_t lseek(int fd, off_t offset, int whence) {
fd_put(d);
rt_set_errno(result);
+
return -1;
}
/* release the ref-count of fd */
fd_put(d);
+
return offset;
}
@@ -246,8 +254,10 @@ int rename(const char *old, const char *new) if (result < 0)
{
rt_set_errno(result);
+
return -1;
}
+
return 0;
}
@@ -267,8 +277,10 @@ int unlink(const char *pathname) if (result < 0)
{
rt_set_errno(result);
+
return -1;
}
+
return 0;
}
@@ -288,8 +300,10 @@ int stat(const char *file, struct stat *buf) if (result < 0)
{
rt_set_errno(result);
+
return -1;
}
+
return result;
}
@@ -308,6 +322,7 @@ int fstat(int fildes, struct stat *buf) if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
+
return -1;
}
@@ -348,6 +363,7 @@ int statfs(const char *path, struct statfs *buf) if (result < 0)
{
rt_set_errno(result);
+
return -1;
}
@@ -372,6 +388,7 @@ int mkdir(const char *path, mode_t mode) if (fd == -1)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
+
return -1;
}
@@ -383,11 +400,13 @@ int mkdir(const char *path, mode_t mode) {
fd_put(d);
rt_set_errno(result);
+
return -1;
}
dfs_file_close(d);
fd_put(d);
+
return 0;
}
#ifdef RT_USING_FINSH
@@ -400,7 +419,7 @@ FINSH_FUNCTION_EXPORT(mkdir, create a directory); *
* @param pathname the path name to be removed.
*
- * @return 0 on sucessfull, others on failed.
+ * @return 0 on successful, others on failed.
*/
int rmdir(const char *pathname)
{
@@ -410,6 +429,7 @@ int rmdir(const char *pathname) if (result < 0)
{
rt_set_errno(result);
+
return -1;
}
@@ -436,6 +456,7 @@ DIR *opendir(const char *name) if (fd == -1)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
+
return RT_NULL;
}
d = fd_get(fd);
@@ -452,10 +473,11 @@ DIR *opendir(const char *name) }
else
{
- rt_memset(t, 0, sizeof(DIR));
- t->fd = fd;
+ rt_memset(t, 0, sizeof(DIR));
+ t->fd = fd;
}
fd_put(d);
+
return t;
}
@@ -485,6 +507,7 @@ struct dirent *readdir(DIR *d) if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
+
return RT_NULL;
}
@@ -505,6 +528,7 @@ struct dirent *readdir(DIR *d) }
fd_put(fd);
+
return (struct dirent *)(d->buf+d->cur);
}
@@ -525,6 +549,7 @@ long telldir(DIR *d) if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
+
return 0;
}
@@ -549,6 +574,7 @@ void seekdir(DIR *d, off_t offset) if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
+
return ;
}
@@ -571,6 +597,7 @@ void rewinddir(DIR *d) if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
+
return ;
}
@@ -597,6 +624,7 @@ int closedir(DIR *d) if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
+
return -1;
}
@@ -609,9 +637,11 @@ int closedir(DIR *d) if (result < 0)
{
rt_set_errno(result);
+
return -1;
}
- else return 0;
+ else
+ return 0;
}
#ifdef DFS_USING_WORKDIR
@@ -632,12 +662,14 @@ int chdir(const char *path) dfs_lock();
rt_kprintf("%s\n", working_directory);
dfs_unlock();
+
return 0;
}
if (rt_strlen(path) > DFS_PATH_MAX)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
+
return -1;
}
@@ -645,6 +677,7 @@ int chdir(const char *path) if (fullpath == RT_NULL)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
+
return -1; /* build path failed */
}
@@ -655,6 +688,7 @@ int chdir(const char *path) rt_free(fullpath);
/* this is a not exist directory */
dfs_unlock();
+
return -1;
}
@@ -692,6 +726,7 @@ char *getcwd(char *buf, size_t size) #else
rt_kprintf("WARNING: not support working directory\n");
#endif
+
return buf;
}
|
