Chinaunix首页 | 论坛 | 博客
  • 博客访问: 542366
  • 博文数量: 150
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-17 00:19
文章分类

全部博文(150)

文章存档

2011年(1)

2009年(14)

2008年(135)

我的朋友

分类: LINUX

2008-08-31 09:39:11

>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) |
给主人留下些什么吧!~~