9 个解决方案
#1
到头文件找找呗,如果没定义肯定会报错啊。。。
没报错说明引用的文件定义了呗
没报错说明引用的文件定义了呗
#2
+1
#3
里面是没有看到的,能帮忙解释一下这个程序吗,下面的
#4
unix书上说作为sysconf(int name)函数,这个name参数只能选择书上那2个表的里面的值,如果是其他的值函数都返回-1,请高手指点一下
#5
代码在下面,函数功能是为路径名动态分配内存,请高手帮忙解释一下
#include "apue.h"
#include <errno.h>
#include <limits.h>
#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_GUESS 1024
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 pathname");
if(sizep!=NULL)
*sizep=size;
return ptr;
}
#include "apue.h"
#include <errno.h>
#include <limits.h>
#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_GUESS 1024
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 pathname");
if(sizep!=NULL)
*sizep=size;
return ptr;
}
#6
你下载一个gnu libc 源码看看sysconf的实现.我给你摘抄了一段:
long int
__sysconf (name)
int name;
{
switch (name)
{
default:
__set_errno (EINVAL);
return -1;
...
case _SC_VERSION:
...
break;
}
__set_errno (ENOSYS);
return -1;
}
#7
man sysconf
grep -rn _SC_VERSION /usr/include
/usr/include/bits/confname.h:133: _SC_VERSION,
/usr/include/bits/confname.h:134:#define _SC_VERSION _SC_VERSION
grep -rn confname.h /usr/include
/usr/include/bits/confname.h:22:# error "Never use <bits/confname.h> directly; include <unistd.h> instead."
/usr/include/unistd.h:554:#include <bits/confname.h>
_SC_VERSION
不过就是unistd.h中定义的一个常量而已。
grep -rn _SC_VERSION /usr/include
/usr/include/bits/confname.h:133: _SC_VERSION,
/usr/include/bits/confname.h:134:#define _SC_VERSION _SC_VERSION
grep -rn confname.h /usr/include
/usr/include/bits/confname.h:22:# error "Never use <bits/confname.h> directly; include <unistd.h> instead."
/usr/include/unistd.h:554:#include <bits/confname.h>
_SC_VERSION
不过就是unistd.h中定义的一个常量而已。
#8
++
#9
书上说“很多程序都要为路径名分配内存”,小弟愚钝,这句话什么意思啊,还望指点啊
#1
到头文件找找呗,如果没定义肯定会报错啊。。。
没报错说明引用的文件定义了呗
没报错说明引用的文件定义了呗
#2
+1
#3
里面是没有看到的,能帮忙解释一下这个程序吗,下面的
#4
unix书上说作为sysconf(int name)函数,这个name参数只能选择书上那2个表的里面的值,如果是其他的值函数都返回-1,请高手指点一下
#5
代码在下面,函数功能是为路径名动态分配内存,请高手帮忙解释一下
#include "apue.h"
#include <errno.h>
#include <limits.h>
#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_GUESS 1024
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 pathname");
if(sizep!=NULL)
*sizep=size;
return ptr;
}
#include "apue.h"
#include <errno.h>
#include <limits.h>
#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_GUESS 1024
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 pathname");
if(sizep!=NULL)
*sizep=size;
return ptr;
}
#6
你下载一个gnu libc 源码看看sysconf的实现.我给你摘抄了一段:
long int
__sysconf (name)
int name;
{
switch (name)
{
default:
__set_errno (EINVAL);
return -1;
...
case _SC_VERSION:
...
break;
}
__set_errno (ENOSYS);
return -1;
}
#7
man sysconf
grep -rn _SC_VERSION /usr/include
/usr/include/bits/confname.h:133: _SC_VERSION,
/usr/include/bits/confname.h:134:#define _SC_VERSION _SC_VERSION
grep -rn confname.h /usr/include
/usr/include/bits/confname.h:22:# error "Never use <bits/confname.h> directly; include <unistd.h> instead."
/usr/include/unistd.h:554:#include <bits/confname.h>
_SC_VERSION
不过就是unistd.h中定义的一个常量而已。
grep -rn _SC_VERSION /usr/include
/usr/include/bits/confname.h:133: _SC_VERSION,
/usr/include/bits/confname.h:134:#define _SC_VERSION _SC_VERSION
grep -rn confname.h /usr/include
/usr/include/bits/confname.h:22:# error "Never use <bits/confname.h> directly; include <unistd.h> instead."
/usr/include/unistd.h:554:#include <bits/confname.h>
_SC_VERSION
不过就是unistd.h中定义的一个常量而已。
#8
++
#9
书上说“很多程序都要为路径名分配内存”,小弟愚钝,这句话什么意思啊,还望指点啊