#include <signal.h>
#include <time.h>
#include <sys/types.h>
+#include <sys/sysmacros.h>
static const char tar_usage[] =
* Open the tar file for reading.
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
- tarFd = STDIN;
+ tarFd = fileno(stdin);
} else
tarFd = open (tarName, O_RDONLY);
int uid;
int gid;
int checkSum;
- int major;
- int minor;
+ unsigned int major;
+ unsigned int minor;
long size;
time_t mtime;
const char *name;
*/
if (extractFlag==FALSE) {
if (verboseFlag==TRUE) {
- printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
- uid, gid, size, timeString (mtime), name);
- } else
- printf ("%s", name);
+ printf ("%s %3d/%-d ", modeString (mode), uid, gid);
+ if( S_ISCHR (mode) || S_ISBLK (mode) )
+ printf ("%4d,%4d %s ", major,minor, timeString (mtime));
+ else
+ printf ("%9ld %s ", size, timeString (mtime));
+ }
+ printf ("%s", name);
if (hardLink)
printf (" (link to \"%s\")", hp->linkName);
if (hardLink) {
if (link (hp->linkName, name) < 0)
perror (name);
-
+ chmod(name, mode);
+ chown(name, uid, gid);
return;
}
#ifdef S_ISLNK
if (symlink (hp->linkName, name) < 0)
perror (name);
+ chmod(name, mode);
+ chown(name, uid, gid);
#else
fprintf (stderr, "Cannot create symbolic links\n");
#endif
return;
}
+ /* Set the umask for this process so it doesn't
+ * screw things up. */
+ umask(0);
+
/*
* If the file is a directory, then just create the path.
*/
if (S_ISDIR (mode)) {
createPath (name, mode);
+ chmod(name, mode);
+ chown(name, uid, gid);
return;
}
/*
* There is a file to write.
- * First create the path to it if necessary with a default permission.
+ * First create the path to it if necessary with default permissions.
*/
createPath (name, 0777);
* Start the output file.
*/
if (tostdoutFlag == TRUE)
- outFd = STDOUT;
+ outFd = fileno(stdout);
else {
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
devFileFlag = TRUE;
outFd = mknod (name, mode, makedev(major, minor) );
}
else if (S_ISFIFO(mode) ) {
+ devFileFlag = TRUE;
outFd = mkfifo(name, mode);
} else {
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
skipFileFlag = TRUE;
return;
}
+ if (tostdoutFlag == FALSE) {
+ fchmod(outFd, mode);
+ fchown(outFd, uid, gid);
+ }
/*
* If the file is empty, then that's all we need to do.
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
tostdoutFlag = TRUE;
- tarFd = STDOUT;
+ tarFd = fileno(stdout);
} else
tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0666);
tarDev = statbuf.st_dev;
tarInode = statbuf.st_ino;
-
+
/*
* Append each file name into the archive file.
* Follow symbolic links for these top level file names.