* this function is a POSIX compliant version, which will close a directory * stream. * * @param d the directory stream. * * @return 0 on successful, -1 on failed. */
| 1137 | * @return 0 on successful, -1 on failed. |
| 1138 | */ |
| 1139 | int closedir(DIR *d) |
| 1140 | { |
| 1141 | int result; |
| 1142 | struct dfs_file *file; |
| 1143 | |
| 1144 | if (d == NULL) |
| 1145 | { |
| 1146 | rt_set_errno(-EBADF); |
| 1147 | return -1; |
| 1148 | } |
| 1149 | |
| 1150 | file = fd_get(d->fd); |
| 1151 | if (file == NULL) |
| 1152 | { |
| 1153 | rt_set_errno(-EBADF); |
| 1154 | return -1; |
| 1155 | } |
| 1156 | |
| 1157 | result = dfs_file_close(file); |
| 1158 | if (result < 0) |
| 1159 | { |
| 1160 | rt_set_errno(result); |
| 1161 | |
| 1162 | return -1; |
| 1163 | } |
| 1164 | else |
| 1165 | { |
| 1166 | fd_release(d->fd); |
| 1167 | rt_free(d); |
| 1168 | } |
| 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | RTM_EXPORT(closedir); |
| 1173 | |
| 1174 | #ifdef DFS_USING_WORKDIR |
no test coverage detected