2 ** Copyright 1998-2003 University of Illinois Board of Trustees
3 ** Copyright 1998-2003 Mark D. Roth
4 ** All rights reserved.
6 ** util.c - miscellaneous utility code for libtar
8 ** Mark D. Roth <roth@uiuc.edu>
9 ** Campus Information Technologies and Educational Services
10 ** University of Illinois at Urbana-Champaign
16 #include <sys/param.h>
24 /* hashing function for pathnames */
26 path_hashfunc(char *key
, int numbuckets
)
34 return (((unsigned int)p
[0]) % numbuckets
);
38 /* matching function for dev_t's */
40 dev_match(dev_t
*dev1
, dev_t
*dev2
)
42 return !memcmp(dev1
, dev2
, sizeof(dev_t
));
46 /* matching function for ino_t's */
48 ino_match(ino_t
*ino1
, ino_t
*ino2
)
50 return !memcmp(ino1
, ino2
, sizeof(ino_t
));
54 /* hashing function for dev_t's */
62 /* hashing function for ino_t's */
64 ino_hash(ino_t
*inode
)
71 ** mkdirhier() - create all directories in a given path
74 ** 1 all directories already exist
75 ** -1 (and sets errno) error
80 char src
[MAXPATHLEN
], dst
[MAXPATHLEN
] = "";
81 char *dirp
, *nextp
= src
;
84 if (strlcpy(src
, path
, sizeof(src
)) > sizeof(src
))
93 while ((dirp
= strsep(&nextp
, "/")) != NULL
)
102 if (mkdir(dst
, 0777) == -1)
115 /* calculate header checksum */
121 for (i
= 0; i
< T_BLOCKSIZE
; i
++)
122 sum
+= ((unsigned char *)(&(t
->th_buf
)))[i
];
123 for (i
= 0; i
< 8; i
++)
124 sum
+= (' ' - (unsigned char)t
->th_buf
.chksum
[i
]);
130 /* string-octal to integer conversion */
132 oct_to_int(char *oct
)
136 sscanf(oct
, "%o", &i
);
142 /* integer to string-octal conversion, no NULL */
144 int_to_oct_nonull(int num
, char *oct
, size_t octlen
)
146 snprintf(oct
, octlen
, "%*lo", octlen
- 1, (unsigned long)num
);
147 oct
[octlen
- 1] = ' ';