|
33 | 33 |
|
34 | 34 | /** |
35 | 35 | * this function is a POSIX compliant version, which will open a file and |
36 | | - * return a file descriptor. |
| 36 | + * return a file descriptor according specified flags. |
37 | 37 | * |
38 | 38 | * @param file the path name of file. |
39 | 39 | * @param flags the file open flags. |
40 | | - * @param mode |
| 40 | + * @param mode ignored parameter |
41 | 41 | * |
42 | 42 | * @return the non-negative integer on successful open, others for failed. |
43 | 43 | */ |
@@ -120,7 +120,8 @@ RTM_EXPORT(close); |
120 | 120 | * @param buf the buffer to save the read data. |
121 | 121 | * @param len the maximal length of data buffer |
122 | 122 | * |
123 | | - * @return the actual read data buffer length |
| 123 | + * @return the actual read data buffer length. If the returned value is 0, it |
| 124 | + * may be reach the end of file, please check errno. |
124 | 125 | */ |
125 | 126 | int read(int fd, void *buf, size_t len) |
126 | 127 | { |
@@ -200,7 +201,7 @@ RTM_EXPORT(write); |
200 | 201 | * @param offset the offset to be seeked. |
201 | 202 | * @param whence the directory of seek. |
202 | 203 | * |
203 | | - * @return the current file position, or -1 on failed. |
| 204 | + * @return the current read/write position in the file, or -1 on failed. |
204 | 205 | */ |
205 | 206 | off_t lseek(int fd, off_t offset, int whence) |
206 | 207 | { |
@@ -336,6 +337,8 @@ RTM_EXPORT(stat); |
336 | 337 | * |
337 | 338 | * @param fildes the file description |
338 | 339 | * @param buf the data buffer to save stat description. |
| 340 | + * |
| 341 | + * @return 0 on successful, -1 on failed. |
339 | 342 | */ |
340 | 343 | int fstat(int fildes, struct stat *buf) |
341 | 344 | { |
@@ -470,7 +473,7 @@ RTM_EXPORT(rmdir); |
470 | 473 | * |
471 | 474 | * @param name the path name to be open. |
472 | 475 | * |
473 | | - * @return the DIR pointer of directory, NULL on open failed. |
| 476 | + * @return the DIR pointer of directory, NULL on open directory failed. |
474 | 477 | */ |
475 | 478 | DIR *opendir(const char *name) |
476 | 479 | { |
@@ -537,12 +540,17 @@ struct dirent *readdir(DIR *d) |
537 | 540 | if (fd == RT_NULL) |
538 | 541 | { |
539 | 542 | rt_set_errno(-DFS_STATUS_EBADF); |
540 | | - |
541 | 543 | return RT_NULL; |
542 | 544 | } |
543 | 545 |
|
544 | | - if (!d->num || |
545 | | - (d->cur += ((struct dirent *)(d->buf + d->cur))->d_reclen) >= d->num) |
| 546 | + if (d->num) |
| 547 | + { |
| 548 | + struct dirent* dirent_ptr; |
| 549 | + dirent_ptr = (struct dirent*)&d->buf[d->cur]; |
| 550 | + d->cur += dirent_ptr->d_reclen; |
| 551 | + } |
| 552 | + |
| 553 | + if (!d->num || d->cur >= d->num) |
546 | 554 | { |
547 | 555 | /* get a new entry */ |
548 | 556 | result = dfs_file_getdents(fd, |
|
0 commit comments