|
|
在我的机子上的输出结果:
$ ./a.out
................................
getcwd failed , size = 7397: File name too long
getcwd failed , size = 7497: File name too long
getcwd failed , size = 7597: File name too long
getcwd failed , size = 7697: File name too long
getcwd failed , size = 7797: File name too long
getcwd failed , size = 7897: File name too long
getcwd failed , size = 7997: File name too long
getcwd failed , size = 8097: File name too long
giving up
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include "ourhdr.h"$
- #define DEPTH 100
- #define MYHOME "/bak/cai"
- #define NAME "alonglonglonglonglonglonglonglonglonglongname"
- #define MAXSZ 8192
- int main(void)
- {
- int i, size;
- char *path;
- if ( chdir(MYHOME) < 0)
- err_sys("chdir failed");
- for ( i = 0; i < DEPTH; i++ ) {
- if ( mkdir(NAME, DIR_MODE) < 0)
- err_sys("mkdir failed, i = %d", i);
- if ( chdir(NAME) < 0)
- err_sys("chdir failed, i = %d", i);
- }
- if ( creat ("afile", FILE_MODE) < 0)
- err_sys("creat failed");
- path = path_alloc(&size);
- for ( ; ; ) {
- if ( getcwd(path, size) != NULL)
- break;
- else {
- err_ret("getcwd failed , size = %d", size);
- size += 100;
- if ( size > MAXSZ)
- err_quit("giving up");
- if ( (path = realloc(path, size) ) == NULL)
- err_sys("realloc error");
- }
- }
- printf("length = %d\n%s\n", strlen(path), path);
- exit(0);
- }
复制代码 |
|