#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
/* /data2/jchern/test */
int mkdir_recursive( char *org_path, char *cur_path, int mode )
{
int ret;
char *p;
if(( p = strchr( cur_path+1, '/' )) != NULL )
*p = '\0';
if( ( ret = mkdir( org_path, mode )) != 0 )
{
switch( errno )
{
case EEXIST : break;
case EFAULT : return 1;
case ENOMEM : return 1;
case EROFS : return 1;
case ELOOP : return 1;
case ENOSPC : return 1;
case ENAMETOOLONG : return 1;
}
}
if( p == NULL ) return 0;
*p = '/';
cur_path = p;
return mkdir_recursive( org_path, cur_path, mode );
}
int mkdir_p( char *fullpath, int mode )
{
char path[1024], *p;
strcpy( path, fullpath );
p = path;
return mkdir_recursive( p, p, mode );
}
int main()
{
mkdir_p( "/data2/jchern/test1/test2", 0755 );
}
'C언어' 카테고리의 다른 글
cpu 사용량 (0) | 2012.05.04 |
---|---|
환경변수 PATH_INFO 활용 (0) | 2012.04.10 |
STL 디버깅( DEBUGGING ) (0) | 2011.12.07 |
sort ( 파일 내부 엔트리 ) (0) | 2011.08.29 |
curl (0) | 2011.08.16 |