diff options
Diffstat (limited to 'tar.c')
-rw-r--r-- | tar.c | 167 |
1 files changed, 1 insertions, 166 deletions
@@ -131,14 +131,10 @@ static void writeHeader(const char * fileName, | |||
131 | static void writeTarFile(int fileCount, char ** fileTable); | 131 | static void writeTarFile(int fileCount, char ** fileTable); |
132 | static void writeTarBlock(const char * buf, int len); | 132 | static void writeTarBlock(const char * buf, int len); |
133 | static BOOL putOctal(char * cp, int len, long value); | 133 | static BOOL putOctal(char * cp, int len, long value); |
134 | extern const char * modeString(int mode); | ||
135 | extern const char * timeString(time_t timeVal); | ||
136 | extern int fullWrite(int fd, const char * buf, int len); | ||
137 | extern int fullRead(int fd, char * buf, int len); | ||
138 | 134 | ||
139 | 135 | ||
140 | extern int | 136 | extern int |
141 | tar_main(struct FileInfo *unused, int argc, char ** argv) | 137 | tar_main(int argc, char ** argv) |
142 | { | 138 | { |
143 | const char * options; | 139 | const char * options; |
144 | 140 | ||
@@ -1258,167 +1254,6 @@ wantFileName(const char * fileName, int fileCount, char ** fileTable) | |||
1258 | 1254 | ||
1259 | 1255 | ||
1260 | 1256 | ||
1261 | /* | ||
1262 | * Return the standard ls-like mode string from a file mode. | ||
1263 | * This is static and so is overwritten on each call. | ||
1264 | */ | ||
1265 | const char * | ||
1266 | modeString(int mode) | ||
1267 | { | ||
1268 | static char buf[12]; | ||
1269 | |||
1270 | strcpy(buf, "----------"); | ||
1271 | |||
1272 | /* | ||
1273 | * Fill in the file type. | ||
1274 | */ | ||
1275 | if (S_ISDIR(mode)) | ||
1276 | buf[0] = 'd'; | ||
1277 | if (S_ISCHR(mode)) | ||
1278 | buf[0] = 'c'; | ||
1279 | if (S_ISBLK(mode)) | ||
1280 | buf[0] = 'b'; | ||
1281 | if (S_ISFIFO(mode)) | ||
1282 | buf[0] = 'p'; | ||
1283 | #ifdef S_ISLNK | ||
1284 | if (S_ISLNK(mode)) | ||
1285 | buf[0] = 'l'; | ||
1286 | #endif | ||
1287 | #ifdef S_ISSOCK | ||
1288 | if (S_ISSOCK(mode)) | ||
1289 | buf[0] = 's'; | ||
1290 | #endif | ||
1291 | |||
1292 | /* | ||
1293 | * Now fill in the normal file permissions. | ||
1294 | */ | ||
1295 | if (mode & S_IRUSR) | ||
1296 | buf[1] = 'r'; | ||
1297 | if (mode & S_IWUSR) | ||
1298 | buf[2] = 'w'; | ||
1299 | if (mode & S_IXUSR) | ||
1300 | buf[3] = 'x'; | ||
1301 | if (mode & S_IRGRP) | ||
1302 | buf[4] = 'r'; | ||
1303 | if (mode & S_IWGRP) | ||
1304 | buf[5] = 'w'; | ||
1305 | if (mode & S_IXGRP) | ||
1306 | buf[6] = 'x'; | ||
1307 | if (mode & S_IROTH) | ||
1308 | buf[7] = 'r'; | ||
1309 | if (mode & S_IWOTH) | ||
1310 | buf[8] = 'w'; | ||
1311 | if (mode & S_IXOTH) | ||
1312 | buf[9] = 'x'; | ||
1313 | |||
1314 | /* | ||
1315 | * Finally fill in magic stuff like suid and sticky text. | ||
1316 | */ | ||
1317 | if (mode & S_ISUID) | ||
1318 | buf[3] = ((mode & S_IXUSR) ? 's' : 'S'); | ||
1319 | if (mode & S_ISGID) | ||
1320 | buf[6] = ((mode & S_IXGRP) ? 's' : 'S'); | ||
1321 | if (mode & S_ISVTX) | ||
1322 | buf[9] = ((mode & S_IXOTH) ? 't' : 'T'); | ||
1323 | |||
1324 | return buf; | ||
1325 | } | ||
1326 | |||
1327 | |||
1328 | /* | ||
1329 | * Get the time string to be used for a file. | ||
1330 | * This is down to the minute for new files, but only the date for old files. | ||
1331 | * The string is returned from a static buffer, and so is overwritten for | ||
1332 | * each call. | ||
1333 | */ | ||
1334 | const char * | ||
1335 | timeString(time_t timeVal) | ||
1336 | { | ||
1337 | time_t now; | ||
1338 | char * str; | ||
1339 | static char buf[26]; | ||
1340 | |||
1341 | time(&now); | ||
1342 | |||
1343 | str = ctime(&timeVal); | ||
1344 | |||
1345 | strcpy(buf, &str[4]); | ||
1346 | buf[12] = '\0'; | ||
1347 | |||
1348 | if ((timeVal > now) || (timeVal < now - 365*24*60*60L)) | ||
1349 | { | ||
1350 | strcpy(&buf[7], &str[20]); | ||
1351 | buf[11] = '\0'; | ||
1352 | } | ||
1353 | |||
1354 | return buf; | ||
1355 | } | ||
1356 | |||
1357 | |||
1358 | |||
1359 | /* | ||
1360 | * Write all of the supplied buffer out to a file. | ||
1361 | * This does multiple writes as necessary. | ||
1362 | * Returns the amount written, or -1 on an error. | ||
1363 | */ | ||
1364 | int | ||
1365 | fullWrite(int fd, const char * buf, int len) | ||
1366 | { | ||
1367 | int cc; | ||
1368 | int total; | ||
1369 | |||
1370 | total = 0; | ||
1371 | |||
1372 | while (len > 0) | ||
1373 | { | ||
1374 | cc = write(fd, buf, len); | ||
1375 | |||
1376 | if (cc < 0) | ||
1377 | return -1; | ||
1378 | |||
1379 | buf += cc; | ||
1380 | total+= cc; | ||
1381 | len -= cc; | ||
1382 | } | ||
1383 | |||
1384 | return total; | ||
1385 | } | ||
1386 | |||
1387 | |||
1388 | /* | ||
1389 | * Read all of the supplied buffer from a file. | ||
1390 | * This does multiple reads as necessary. | ||
1391 | * Returns the amount read, or -1 on an error. | ||
1392 | * A short read is returned on an end of file. | ||
1393 | */ | ||
1394 | int | ||
1395 | fullRead(int fd, char * buf, int len) | ||
1396 | { | ||
1397 | int cc; | ||
1398 | int total; | ||
1399 | |||
1400 | total = 0; | ||
1401 | |||
1402 | while (len > 0) | ||
1403 | { | ||
1404 | cc = read(fd, buf, len); | ||
1405 | |||
1406 | if (cc < 0) | ||
1407 | return -1; | ||
1408 | |||
1409 | if (cc == 0) | ||
1410 | break; | ||
1411 | |||
1412 | buf += cc; | ||
1413 | total+= cc; | ||
1414 | len -= cc; | ||
1415 | } | ||
1416 | |||
1417 | return total; | ||
1418 | } | ||
1419 | |||
1420 | |||
1421 | |||
1422 | #endif | 1257 | #endif |
1423 | /* END CODE */ | 1258 | /* END CODE */ |
1424 | 1259 | ||