| 160 | } |
| 161 | |
| 162 | int UTIL_setFileStat(const char *filename, const stat_t *statbuf) |
| 163 | { |
| 164 | int res = 0; |
| 165 | |
| 166 | stat_t curStatBuf; |
| 167 | if (!UTIL_stat(filename, &curStatBuf) || !UTIL_isRegularFileStat(&curStatBuf)) |
| 168 | return -1; |
| 169 | |
| 170 | /* set access and modification times */ |
| 171 | /* We check that st_mtime is a macro here in order to give us confidence |
| 172 | * that struct stat has a struct timespec st_mtim member. We need this |
| 173 | * check because there are some platforms that claim to be POSIX 2008 |
| 174 | * compliant but which do not have st_mtim... */ |
| 175 | #if (PLATFORM_POSIX_VERSION >= 200809L) && defined(st_mtime) |
| 176 | { |
| 177 | /* (atime, mtime) */ |
| 178 | struct timespec timebuf[2] = { {0, UTIME_NOW} }; |
| 179 | timebuf[1] = statbuf->st_mtim; |
| 180 | res += utimensat(AT_FDCWD, filename, timebuf, 0); |
| 181 | } |
| 182 | #else |
| 183 | { |
| 184 | struct utimbuf timebuf; |
| 185 | timebuf.actime = time(NULL); |
| 186 | timebuf.modtime = statbuf->st_mtime; |
| 187 | res += utime(filename, &timebuf); |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | #if !defined(_WIN32) |
| 192 | res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */ |
| 193 | #endif |
| 194 | |
| 195 | res += UTIL_chmod(filename, &curStatBuf, statbuf->st_mode & 07777); /* Copy file permissions */ |
| 196 | |
| 197 | errno = 0; |
| 198 | return -res; /* number of errors is returned */ |
| 199 | } |
| 200 | |
| 201 | int UTIL_isDirectory(const char* infilename) |
| 202 | { |
no test coverage detected