Chinaunix首页 | 论坛 | 博客
  • 博客访问: 492934
  • 博文数量: 80
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1916
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-11 22:01
个人简介

从事实时计算多年,熟悉jstorm/spark/flink/kafka/rocketMq, 热衷于开源,希望在这里和前辈们一起学习与分享,得到长足的进步!邮箱:hustfxj@gmail.com 我的githup地址是:https://github.com/hustfxj。欢迎和大家一起交流探讨问题。

文章分类

全部博文(80)

文章存档

2017年(11)

2015年(3)

2014年(33)

2013年(33)

分类: LINUX

2014-01-06 15:09:14

在《UNIX环境高级编程》学习中,在第四章的程序清单4-7中,发现了一个“错误”。发现即使apue.h中声明了path_alloc()这个函数,但是在编译程序清单时还是会提示path_alloc()未定义。这其实并不是错误,因为我本来就没有这个函数的实现。

如果我在第二章看得仔细的话,就能发现原来path_alloc()的实现在程序清单2-3中。

现在自己把函数实现贴出来,以示警告:

#include    "apue.h"
#include    
#include    


#ifdef PATH_MAX
static int pathmax = PATH_MAX;
#else
static int pathmax = 0;
#endif


#define SUSV3 200112L


static long posix_version = 0;
#define PATH_MAX_GUESS1024


char    *path_alloc(int *sizep)
{
char    *ptr;
int size;


if(posix_version == 0)
posix_version = sysconf(_SC_VERSION);


if(pathmax == 0){
errno = 0;
if((pathmax = pathconf("/", _PC_PATH_MAX)) < 0){
if(errno == 0)
pathmax = PATH_MAX_GUESS;
else err_sys("pathconf error for _PC_PATH_MAX");
} else {
pathmax++;
}
}
if(posix_version < SUSV3)
size = pathmax + 1;
else size = pathmax;
if((ptr = malloc(size)) == NULL)
err_sys("malloc error for pathname");
if(sizep != NULL)
*sizep = size;
return(ptr);
}

阅读(4378) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~