>excises:4.16
Does the UNIX System have a fundamental limitation on the depth
of a directory tree? To find out, write a program that creates a directory and
then changes to that directory, in a loop. Make certain that the length of the
absolute pathname of the leaf of this directory is greater than
your system's PATH_MAX limit. Can you call getcwd to fetch the
directory's pathname? How do the standard UNIX System tools deal with this long
pathname? Can you archive the directory using either tar or
cpio?
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#define DEPTH 100
#define PATH "/home/qing/lab_process"
#define NAME "longlonglonglonglonglonglonglonglonglongname"
#define MAXLENGTH 8192
int main( int argc , char *argv[] )
{
int i;
char path_buffer[MAXLENGTH];
if( chdir(PATH)<0 ){
perror( "change main directory failed" );
return;
}
for( i=0; i<DEPTH; i++){
if( mkdir( NAME ,S_IRUSR|S_IWUSR|S_IXUSR ) <0 ){
perror( "make directory failed" );
return;
}
if( chdir( NAME ) <0 ){
perror( "change a new directory" );
return;
}
}
printf( "obtain current directory!" );
if( getcwd(path_buffer , MAXLENGTH)==NULL ){
perror( "get current directory failed!" );
return ;
}
puts( "current directory:" );
//puts( path_buffer );
printf( "pathbuffer:length--%d \nstring:%s", strlen(path_buffer) , path_buffer );
puts( "\n" );
return 0;
}
|
显示:
get current directory failed!: File name too long
阅读(1088) | 评论(0) | 转发(0) |