⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 longpath.c

📁 APUE(第二版)的随书源代码,与第一版的代码相比增加了一些章节的代码(详见第二版的说明)
💻 C
字号:
#include	<sys/types.h>#include	<sys/stat.h>#include	<fcntl.h>#include	"ourhdr.h"#define	DEPTH	100			/* directory depth */#define	MYHOME	"/home/stevens"#define	NAME	"alonglonglonglonglonglonglonglonglonglongname"intmain(void){	int		i, size;	char	*path;	if (chdir(MYHOME) < 0)		err_sys("chdir error");	for (i = 0; i < DEPTH; i++) {		if (mkdir(NAME, DIR_MODE) < 0)			err_sys("mkdir failed, i = %d", i);		if (chdir(NAME) < 0)			err_sys("chdir failed, i = %d", i);	}	if (creat("afile", FILE_MODE) < 0)		err_sys("creat error");	/*	 * The deep directory is created, with a file at the leaf.	 * Now let's try and obtain its pathname.	 */	path = path_alloc(&size);	for ( ; ; ) {		if (getcwd(path, size) != NULL)			break;		else {			err_ret("getcwd failed, size = %d", size);			size += 100;			if ( (path = realloc(path, size)) == NULL)				err_sys("realloc error");		}	}	printf("length = %d\n%s\n", strlen(path), path);	exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -