Changeset 51 in kBuild for trunk/src/kmk/util.c
- Timestamp:
- Apr 7, 2003 1:30:32 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/util.c
r35 r51 5 5 #ifndef lint 6 6 static char rcsid[] = "$FreeBSD: src/usr.bin/make/util.c,v 1.5.2.2 2001/02/13 03:13:58 will Exp $"; 7 #define KLIBFILEDEF rcsid 7 8 #endif 8 9 … … 27 28 static char buf[100]; 28 29 if (e < 0 || e >= sys_nerr) { 29 30 30 sprintf(buf, "Unknown error %d", e); 31 return buf; 31 32 } 32 33 else 33 34 return sys_errlist[e]; 34 35 } 35 36 #endif … … 50 51 51 52 if (str == NULL) 52 53 return NULL; 53 54 len = strlen(str) + 1; 54 55 if ((p = emalloc(len)) == NULL) 55 56 return NULL; 56 57 57 58 return memcpy(p, str, len); … … 60 61 #endif 61 62 62 #if defined(sun) || defined(__hpux) || defined(__sgi) || defined(__EMX__) || (defined(OS2) && defined(__IBMC__)) 63 #ifndef USE_KLIB 64 #if defined(sun) || defined(__hpux) || defined(__sgi) || defined(__EMX__) 63 65 64 66 int … … 75 77 76 78 if (ptr == NULL) 77 79 return -1; 78 80 79 81 p = ptr; 80 82 81 83 while (*name) 82 84 *p++ = *name++; 83 85 84 86 *p++ = '='; 85 87 86 88 while (*value) 87 89 *p++ = *value++; 88 90 89 91 *p = '\0'; … … 93 95 return len; 94 96 } 97 #endif 95 98 #endif 96 99 … … 157 160 158 161 /* strrcpy(): 159 * 162 * Like strcpy, going backwards and returning the new pointer 160 163 */ 161 164 static char * … … 166 169 167 170 while (len) 168 171 *--ptr = str[--len]; 169 172 170 173 return (ptr); … … 185 188 /* find the inode of root */ 186 189 if (stat("/", &st_root) == -1) { 187 188 189 190 (void) sprintf(pathname, 191 "getwd: Cannot stat \"/\" (%s)", strerror(errno)); 192 return (NULL); 190 193 } 191 194 pathbuf[MAXPATHLEN - 1] = '\0'; … … 196 199 /* find the inode of the current directory */ 197 200 if (lstat(".", &st_cur) == -1) { 198 199 200 201 (void) sprintf(pathname, 202 "getwd: Cannot stat \".\" (%s)", strerror(errno)); 203 return (NULL); 201 204 } 202 205 nextpathptr = strrcpy(nextpathptr, "../"); … … 205 208 for (;;) { 206 209 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 210 /* look if we found root yet */ 211 if (st_cur.st_ino == st_root.st_ino && 212 DEV_DEV_COMPARE(st_cur.st_dev, st_root.st_dev)) { 213 (void) strcpy(pathname, *pathptr != '/' ? "/" : pathptr); 214 return (pathname); 215 } 216 217 /* open the parent directory */ 218 if (stat(nextpathptr, &st_dotdot) == -1) { 219 snprintf(pathname, sizeof(pathname), 220 "getwd: Cannot stat directory \"%s\" (%s)", 221 nextpathptr, strerror(errno)); 222 return (NULL); 223 } 224 if ((dp = opendir(nextpathptr)) == NULL) { 225 snprintf(pathname, sizeof(pathname), 226 "getwd: Cannot open directory \"%s\" (%s)", 227 nextpathptr, strerror(errno)); 228 return (NULL); 229 } 230 231 /* look in the parent for the entry with the same inode */ 232 if (DEV_DEV_COMPARE(st_dotdot.st_dev, st_cur.st_dev)) { 233 /* Parent has same device. No need to stat every member */ 234 for (d = readdir(dp); d != NULL; d = readdir(dp)) 235 if (d->d_fileno == st_cur.st_ino) 236 break; 237 } 238 else { 239 /* 240 * Parent has a different device. This is a mount point so we 241 * need to stat every member 242 */ 243 for (d = readdir(dp); d != NULL; d = readdir(dp)) { 244 if (ISDOT(d->d_name) || ISDOTDOT(d->d_name)) 245 continue; 246 (void) strcpy(cur_name_add, d->d_name); 247 if (lstat(nextpathptr, &st_next) == -1) { 248 snprintf(pathname, sizeof(pathname), "getwd: Cannot stat \"%s\" (%s)", 249 d->d_name, strerror(errno)); 250 (void) closedir(dp); 251 return (NULL); 252 } 253 /* check if we found it yet */ 254 if (st_next.st_ino == st_cur.st_ino && 255 DEV_DEV_COMPARE(st_next.st_dev, st_cur.st_dev)) 256 break; 257 } 258 } 259 if (d == NULL) { 260 (void) sprintf(pathname, "getwd: Cannot find \".\" in \"..\""); 261 (void) closedir(dp); 262 return (NULL); 263 } 264 st_cur = st_dotdot; 265 pathptr = strrcpy(pathptr, d->d_name); 266 pathptr = strrcpy(pathptr, "/"); 267 nextpathptr = strrcpy(nextpathptr, "../"); 268 (void) closedir(dp); 269 *cur_name_add = '\0'; 267 270 } 268 271 } /* end getwd */ … … 336 339 337 340 if (sigaction(s, &sa, &osa) == -1) 338 341 return SIG_ERR; 339 342 else 340 341 } 342 343 #endif 343 return osa.sa_handler; 344 } 345 346 #endif
Note:
See TracChangeset
for help on using the changeset viewer.