©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

c3/bigdir.c

Go to the documentation of this file.
00001 /*
00002     Long-pathname test program
00003     AUP2, Sec. 3.6.4 (not in book)
00004 
00005     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00006     May be copied only for purposes and under conditions described
00007     on the Web page www.basepath.com/aup/copyright.htm.
00008 
00009     The Example Files are provided "as is," without any warranty;
00010     without even the implied warranty of merchantability or fitness
00011     for a particular purpose. The author and his publisher are not
00012     responsible for any damages, direct or incidental, resulting
00013     from the use or non-use of these Example Files.
00014 
00015     The Example Files may contain defects, and some contain deliberate
00016     coding mistakes that were included for educational reasons.
00017     You are responsible for determining if and how the Example Files
00018     are to be used.
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 }

Generated on Fri Apr 23 10:56:55 2004 for AUP2 Example Source by doxygen 1.3.1