More stuff.
This commit is contained in:
167
archival/tar.c
167
archival/tar.c
@ -131,14 +131,10 @@ static void writeHeader(const char * fileName,
|
||||
static void writeTarFile(int fileCount, char ** fileTable);
|
||||
static void writeTarBlock(const char * buf, int len);
|
||||
static BOOL putOctal(char * cp, int len, long value);
|
||||
extern const char * modeString(int mode);
|
||||
extern const char * timeString(time_t timeVal);
|
||||
extern int fullWrite(int fd, const char * buf, int len);
|
||||
extern int fullRead(int fd, char * buf, int len);
|
||||
|
||||
|
||||
extern int
|
||||
tar_main(struct FileInfo *unused, int argc, char ** argv)
|
||||
tar_main(int argc, char ** argv)
|
||||
{
|
||||
const char * options;
|
||||
|
||||
@ -1258,167 +1254,6 @@ wantFileName(const char * fileName, int fileCount, char ** fileTable)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Return the standard ls-like mode string from a file mode.
|
||||
* This is static and so is overwritten on each call.
|
||||
*/
|
||||
const char *
|
||||
modeString(int mode)
|
||||
{
|
||||
static char buf[12];
|
||||
|
||||
strcpy(buf, "----------");
|
||||
|
||||
/*
|
||||
* Fill in the file type.
|
||||
*/
|
||||
if (S_ISDIR(mode))
|
||||
buf[0] = 'd';
|
||||
if (S_ISCHR(mode))
|
||||
buf[0] = 'c';
|
||||
if (S_ISBLK(mode))
|
||||
buf[0] = 'b';
|
||||
if (S_ISFIFO(mode))
|
||||
buf[0] = 'p';
|
||||
#ifdef S_ISLNK
|
||||
if (S_ISLNK(mode))
|
||||
buf[0] = 'l';
|
||||
#endif
|
||||
#ifdef S_ISSOCK
|
||||
if (S_ISSOCK(mode))
|
||||
buf[0] = 's';
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Now fill in the normal file permissions.
|
||||
*/
|
||||
if (mode & S_IRUSR)
|
||||
buf[1] = 'r';
|
||||
if (mode & S_IWUSR)
|
||||
buf[2] = 'w';
|
||||
if (mode & S_IXUSR)
|
||||
buf[3] = 'x';
|
||||
if (mode & S_IRGRP)
|
||||
buf[4] = 'r';
|
||||
if (mode & S_IWGRP)
|
||||
buf[5] = 'w';
|
||||
if (mode & S_IXGRP)
|
||||
buf[6] = 'x';
|
||||
if (mode & S_IROTH)
|
||||
buf[7] = 'r';
|
||||
if (mode & S_IWOTH)
|
||||
buf[8] = 'w';
|
||||
if (mode & S_IXOTH)
|
||||
buf[9] = 'x';
|
||||
|
||||
/*
|
||||
* Finally fill in magic stuff like suid and sticky text.
|
||||
*/
|
||||
if (mode & S_ISUID)
|
||||
buf[3] = ((mode & S_IXUSR) ? 's' : 'S');
|
||||
if (mode & S_ISGID)
|
||||
buf[6] = ((mode & S_IXGRP) ? 's' : 'S');
|
||||
if (mode & S_ISVTX)
|
||||
buf[9] = ((mode & S_IXOTH) ? 't' : 'T');
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get the time string to be used for a file.
|
||||
* This is down to the minute for new files, but only the date for old files.
|
||||
* The string is returned from a static buffer, and so is overwritten for
|
||||
* each call.
|
||||
*/
|
||||
const char *
|
||||
timeString(time_t timeVal)
|
||||
{
|
||||
time_t now;
|
||||
char * str;
|
||||
static char buf[26];
|
||||
|
||||
time(&now);
|
||||
|
||||
str = ctime(&timeVal);
|
||||
|
||||
strcpy(buf, &str[4]);
|
||||
buf[12] = '\0';
|
||||
|
||||
if ((timeVal > now) || (timeVal < now - 365*24*60*60L))
|
||||
{
|
||||
strcpy(&buf[7], &str[20]);
|
||||
buf[11] = '\0';
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Write all of the supplied buffer out to a file.
|
||||
* This does multiple writes as necessary.
|
||||
* Returns the amount written, or -1 on an error.
|
||||
*/
|
||||
int
|
||||
fullWrite(int fd, const char * buf, int len)
|
||||
{
|
||||
int cc;
|
||||
int total;
|
||||
|
||||
total = 0;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
cc = write(fd, buf, len);
|
||||
|
||||
if (cc < 0)
|
||||
return -1;
|
||||
|
||||
buf += cc;
|
||||
total+= cc;
|
||||
len -= cc;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Read all of the supplied buffer from a file.
|
||||
* This does multiple reads as necessary.
|
||||
* Returns the amount read, or -1 on an error.
|
||||
* A short read is returned on an end of file.
|
||||
*/
|
||||
int
|
||||
fullRead(int fd, char * buf, int len)
|
||||
{
|
||||
int cc;
|
||||
int total;
|
||||
|
||||
total = 0;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
cc = read(fd, buf, len);
|
||||
|
||||
if (cc < 0)
|
||||
return -1;
|
||||
|
||||
if (cc == 0)
|
||||
break;
|
||||
|
||||
buf += cc;
|
||||
total+= cc;
|
||||
len -= cc;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
/* END CODE */
|
||||
|
||||
|
Reference in New Issue
Block a user