+ -
当前位置:首页 → 问答吧 → PATH_MAX没有定义

PATH_MAX没有定义

时间:2011-07-07

来源:互联网

#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
main()
{
  int n;
  struct hostent *h;
  char **p;
  char hostname[PATH_MAX];

  if(gethostname(hostname,PATH_MAX) < 0)
  {
  fprintf(stderr,"gethostname failed:%s\n",strerror(errno));
  exit(0);
  }

  if((h = gethostbyname(hostname)) == NULL)
  {
  fprintf(stderr,"gethostbyname failed:%s\n",strerror(errno));
  exit(0);
  }

  fprintf(stderr,"Host name:%s\n",h->h_name);
  for(n=0,p=h->h_aliases; *p != NULL; p++,n++)
  {
  fprintf(stderr,"Alias name %d:%s\n",n+1,*p);
  }
  for(n=0; n< h->h_length/sizeof(int); n++)
  {
  fprintf(stderr,"Ip address %d:%s\n",n+1,inet_ntoa(*((struct in_addr *)(h->h_addr_list[n]))));
  }
  return;
}
这段程序在使用gcc编译以后出现如下信息:
host.c: In function ‘main’:
host.c:11:19: error: ‘PATH_MAX’ undeclared (first use in this function)
host.c:11:19: note: each undeclared identifier is reported only once for each function it appears in
host.c:15:9: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
host.c:21:9: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
host.c:32:69: warning: format ‘%s’ expects type ‘char *’, but argument 4 has type ‘int’
PATH_MAX如何定义?这段程序的第15、21、32行的warning如何修改?

作者: scintist2010   发布时间: 2011-07-07

PATH_MAX 是在windef.h文件中定义。。需要包括些文件或者
自行定义
#define MAX_PATH 260

作者: c395565746c   发布时间: 2011-07-07