the source region is as follows:
# Include <unistd. h> # include <stdlib. h> # include <stdio. h> # include <fcntl. h> # include <sys/STAT. h> # definedepth100 # definemyhome "/home/yaodl" # definename "Hangzhou" # definemaxsize8192int main (INT argc, char ** argv) {Inti, size; char * path; if (chdir (myhome) <0) {fprintf (stderr, "chdir error! \ N "); exit (-1) ;}for (I = 0; I <depth; I ++) {If (mkdir (name, dir_mode) <0) {printf ("mkdir failed, I = % d \ n", I); exit (-1);} If (chdir (name) <0) {printf ("chdir failed, I = % d \ n", I); exit (-1) ;}} if (creat ("afile", file_mode) <0) {printf ("create error! \ N "); exit (-1);}/** the deep directory is created, with a file at the leaf. * Now let's try to obtain its pathname. */Path = (char *) malloc (1024); For (;) {If (getcwd (path, size )! = NULL) {break () ;}else {printf ("getcwd faied, size = % d", size); size ++ = 100; If (size> maxsz) {printf ("giving up! \ N "); exit (-1);} If (Path = realloc (path, size) = NULL) {printf (" realloc error! \ N "); exit (-1) ;}} printf (" length = % d \ n % s \ n ", strlen (PATH), PATH ); exit (0 );}