| 114 | } |
| 115 | |
| 116 | void scan_dir(ScanState *s, const char *path) |
| 117 | { |
| 118 | FILE *f = s->f; |
| 119 | DIR *dirp; |
| 120 | struct dirent *de; |
| 121 | const char *name; |
| 122 | struct stat st; |
| 123 | char *path1; |
| 124 | uint32_t mode, v; |
| 125 | |
| 126 | dirp = opendir(path); |
| 127 | if (!dirp) { |
| 128 | perror(path); |
| 129 | exit(1); |
| 130 | } |
| 131 | for(;;) { |
| 132 | de = readdir(dirp); |
| 133 | if (!de) |
| 134 | break; |
| 135 | name = de->d_name; |
| 136 | if (!strcmp(name, ".") || !strcmp(name, "..")) |
| 137 | continue; |
| 138 | path1 = compose_path(path, name); |
| 139 | if (lstat(path1, &st) < 0) { |
| 140 | perror(path1); |
| 141 | exit(1); |
| 142 | } |
| 143 | |
| 144 | mode = st.st_mode & 0xffff; |
| 145 | fprintf(f, "%06o %u %u", |
| 146 | mode, |
| 147 | (int)st.st_uid, |
| 148 | (int)st.st_gid); |
| 149 | if (S_ISCHR(mode) || S_ISBLK(mode)) { |
| 150 | fprintf(f, " %u %u", |
| 151 | (int)major(st.st_rdev), |
| 152 | (int)minor(st.st_rdev)); |
| 153 | } |
| 154 | if (S_ISREG(mode)) { |
| 155 | fprintf(f, " %" PRIu64, st.st_size); |
| 156 | } |
| 157 | /* modification time (at most ms resolution) */ |
| 158 | fprintf(f, " %u", (int)st.st_mtim.tv_sec); |
| 159 | v = st.st_mtim.tv_nsec; |
| 160 | if (v != 0) { |
| 161 | fprintf(f, "."); |
| 162 | while (v != 0) { |
| 163 | fprintf(f, "%u", v / 100000000); |
| 164 | v = (v % 100000000) * 10; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | fprintf(f, " "); |
| 169 | print_str(f, name); |
| 170 | if (S_ISLNK(mode)) { |
| 171 | char buf[1024]; |
| 172 | int len; |
| 173 | len = readlink(path1, buf, sizeof(buf) - 1); |
no test coverage detected