免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2278 | 回复: 5
打印 上一主题 下一主题

sun的man手册好粗心呀 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-11 17:02 |只看该作者 |倒序浏览
$man scandir
显示
SunOS/BSD Compatibility Library Functions           scandir(3UCB)

NAME
     scandir, alphasort - scan a directory

SYNOPSIS
     /usr/ucb/cc [ flag... ] file...
     #include <sys/types.h>;
     #include <sys/dir.h>;

     int scandir(dirname, namelist, select, dcomp);
     char *dirname;
     struct direct *(*namelist[]);
     int (*select(.),(*dcomp)();

     int alphasort(d1, d2);
     struct direct **d1, **d2;

害得偶查半天,原来struct direct写错了,正确得应该是dirent

论坛徽章:
0
2 [报告]
发表于 2003-05-11 17:03 |只看该作者

sun的man手册好粗心呀

gcc怎么编译不通过,有大侠指点一下吗?
#include <stdio.h>;
#include <stdlib.h>;
#include <unistd.h>;
#include <errno.h>;
#include <sys/types.h>;
#include <dirent.h>;
#include <string.h>;

/*extern int scandir(const char *dirname, struct dirent ***namelist, \
   int (*select)(struct dirent *), int (*compar)(const void *, const void *));
*/
extern int scandir(const char *dirname, struct dirent *(*namelist[]),int (*select)(struct dirent *), int (*compar)(struct dirent **, struct dirent **));

extern int alphasort(const void *d1, const void *d2);

/*
* Select only those direntory entries that start with
* 'h'to demonstrate the selection ability :
*/

static int my_select(struct dirent *dp)
{
  if ( dp->;d_name[0] != 'h')
    return 0; /* Don't include this */
  return 1; /* else include this one*/
}

/*
* Sort entries in reverse order for demonstration
* purposes :
*/
static int my_compar(struct dirent **d1,struct dirent **d2)
{
  struct dirent *dir1 = *d1;
  struct dirent *dir2 = *d2;
  /*
   * Reverse the comparison by reversing
   * dir2 with dir1 in the strcmp(3) call:
   */
  return strcmp(dir2->;d_name,dir1->;d_name);
}

/*
* A good test is the direntory /etc :
*/
int main(int argc,char **argv)
{
  int x; /* Work index */
  int n; /* namelist[n] */
  struct dirent **namelist; /* List of names */
  
  if ( argc < 2 )
  {
    fputs("A pathname argument is required.\n, Try /etc for the direntory.\n",stderr);
    return 1;
  }
  
  /*
   * Scan the direntory given :
   */
  n = scandir(argv[1],&namelist,my_select,my_compar);
  
  /*
   * Report the direntory entries :
   */
  printf("%d entries for %s:\n",n,argv[1]);
  for ( x=0; x<n; ++x )
    printf("%3d: %s\n",x,namelist[x]->;d_name);
   
  if ( n >; 0 )
  {
    for ( x=0; x<n; ++x )
      free(namelist[x]); /* Release entry */
    free(namelist); /* Release the array */
  }
  return 0;
}

编译
$g++ scandir.c
后返回下面的错误

未定义 文件中的
符号 在文件中
scandir(char const*, dirent***, int (*)(dirent*), int (*)(dirent**, dirent**))/var/tmp//ccdpIoK3.o
ld: 致命的: 符号参照错误. 没有输出被写入a.out
collect2: ld returned 1 exit status

是什么错误呀?请指教。

论坛徽章:
0
3 [报告]
发表于 2003-05-11 17:37 |只看该作者

sun的man手册好粗心呀

指点一下啦,困惑中...

论坛徽章:
0
4 [报告]
发表于 2003-05-11 20:16 |只看该作者

sun的man手册好粗心呀

没#include <sys/dir.h>;

论坛徽章:
0
5 [报告]
发表于 2010-12-23 10:46 |只看该作者
根据man帮助,只支持用 /usr/ucb/cc 进行编译。不支持gcc编译。

ucb是早期的系统了。

我找到 scandir的源代码

http://www.hackchina.com/r/160164/scandir.c__html

进行了兼容。

论坛徽章:
0
6 [报告]
发表于 2010-12-28 14:38 |只看该作者
那個man page 是 Sun OS (BSD) 時代的產物, 跟現在的Solaris (SVR4)差很多...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP