00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <unistd.h>
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <string.h>
00025 #include <errno.h>
00026 #include <sys/stat.h>
00027
00028 int main(void)
00029 {
00030 char name[201];
00031 char path[10000], path2[sizeof(path)];
00032 long max_path;
00033 int i;
00034
00035 (void)system("rm -rf xxxxxxxxxxxxxxxxxxxxxxxxxx*");
00036 errno = 0;
00037 max_path = pathconf(".", _PC_PATH_MAX);
00038 if (max_path == -1) {
00039 if (errno == 0) {
00040 printf("No limit on path\n");
00041 exit(EXIT_SUCCESS);
00042 }
00043 else {
00044 perror("pathconf");
00045 exit(EXIT_FAILURE);
00046 }
00047 }
00048 if (max_path > sizeof(path) - 1) {
00049 printf("Recompile with a bigger path buffer\n");
00050 exit(EXIT_SUCCESS);
00051 }
00052 if (getcwd(path2, sizeof(path2) - 1) == NULL) {
00053 perror("getcwd");
00054 exit(EXIT_FAILURE);
00055 }
00056 memset(name, 'x', sizeof(name) - 1);
00057 name[sizeof(name) - 1] = '\0';
00058 for (i = 0; i < 30; i++) {
00059 if (mkdir(name, 0700) == -1 || chdir(name) == -1) {
00060 perror("mkdir or chdir");
00061 exit(EXIT_FAILURE);
00062 }
00063 strcat(path2, "/");
00064 strcat(path2, name);
00065 }
00066 if (access(path2, F_OK) == -1 && errno == ENAMETOOLONG)
00067 printf("access returns ENAMETOOLONG, as expected\n");
00068 if (getcwd(path, sizeof(path) - 1) == NULL) {
00069 perror("getcwd 2");
00070 exit(EXIT_FAILURE);
00071 }
00072 if (strcmp(path, path2) == 0)
00073 printf("getcwd returned the correct path\n");
00074 printf("max_path = %ld; strlen(path) = %d\n", max_path, strlen(path));
00075 (void)system("rm -rf xxxxxxxxxxxxxxxxxxxxxxxxxx*");
00076 exit(EXIT_SUCCESS);
00077 }