LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2107|回复: 20

c在linux下如何调用api ?

[复制链接]
发表于 2004-6-9 00:16:53 | 显示全部楼层 |阅读模式
如书中说到:

#include<stdio.h>
#include<sys/utsname.h>

main(void)
{
        struct utsname myname;
        uname(&myname);

        printf("SYS_NMLN = %d\n",SYS_NMLN);
}

请问这是如何调用api ? 单靠个#include<sys/utsname.h>

那请问怎么知道uname的头文件是sys/utsname.h

我要使用到其他命令时该使用什么头文件 ? 如何知道 ?

是不是知道了后直接使用头文件就可以该命令 ?

google不出来啊,所以跑到这里问了,,,,希望大虾们可以帮到我
发表于 2004-6-9 00:22:08 | 显示全部楼层
*nix使用系统调用函数作为系统接口。
 楼主| 发表于 2004-6-9 00:33:14 | 显示全部楼层
最初由 home_king 发表
*nix使用系统调用函数作为系统接口。



这句话怎么解释啊,,听不懂  

以后我想使用到其他命令时该如何查询用哪个头文件 ?
发表于 2004-6-9 09:08:36 | 显示全部楼层
man xxx
 楼主| 发表于 2004-6-9 12:53:06 | 显示全部楼层
man 出来也没有说啊,,有没其他办法 ?
发表于 2004-6-9 17:53:31 | 显示全部楼层
最初由 shell 发表
man 出来也没有说啊,,有没其他办法 ?

man是有的。
另外,使用grep也行。
比如,寻找fork的头文件。

  1. grep -r ' fork([0-9a-zA-Z]\+) ' /usr/include
复制代码
 楼主| 发表于 2004-6-9 19:39:00 | 显示全部楼层
谢谢你

还有其他办法吗 ? 我不知道怎么搜索这些方法,,,,
发表于 2004-6-9 20:15:42 | 显示全部楼层
直接使用系统调用只能用汇编,而且是使用系统调用号来调用。为了使用上的方便,一般都提供了与系统调用同名的库函数。如果要知道使用这些库函数需要那些头文件,直接man一下最方便。
发表于 2004-6-9 20:46:38 | 显示全部楼层
在网上查找库函数说明也很方便。
http://www.linuxsir.cn/bbs/showt ... d=655996#post655996
 楼主| 发表于 2004-6-10 02:08:14 | 显示全部楼层
j
'     ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information  about  the FILEs (the current directory by default).
       Sort entries alphabetically if none of -cftuSUX nor --sort.

       Mandatory arguments to long options are  mandatory  for  short  options
       too.

       -a, --all
              do not hide entries starting with .

       -A, --almost-all
              do not list implied . and ..

       --author
              print the author of each file

       -b, --escape
              print octal escapes for nongraphic characters

       --block-size=SIZE
              use SIZE-byte blocks

       -B, --ignore-backups
              do not list implied entries ending with ~

       -c     with -lt: sort by, and show, ctime (time of last modification of
              file status information) with -l: show ctime and  sort  by  name
              otherwise: sort by ctime

       -C     list entries by columns

       --color[=WHEN]
              control  whether  color is used to distinguish file types.  WHEN
              may be `never', `always', or `auto'

       -d, --directory
              list directory entries instead of contents

       -D, --dired
              generate output designed for Emacs' dired mode

       -f     do not sort, enable -aU, disable -lst

       -F, --classify
              append indicator (one of */=@|) to entries

       --format=WORD
              across -x, commas -m, horizontal -x, long -l, single-column  -1,
              verbose -l, vertical -C

       --full-time
              like -l --time-style=full-iso

       -g     like -l, but do not list owner

       -G, --no-group
              inhibit display of group information

       -h, --human-readable
              print sizes in human readable format (e.g., 1K 234M 2G)

       --si   likewise, but use powers of 1000 not 1024

       -H, --dereference-command-line
              follow symbolic links on the command line

       --indicator-style=WORD append indicator with style WORD to entry names:
              none (default), classify (-F), file-type (-p)

       -i, --inode
              print index number of each file

       -I, --ignore=PATTERN
              do not list implied entries matching shell PATTERN

       -k     like --block-size=1K

       -l     use a long listing format

       -L, --dereference
              when showing file information for a symbolic link, show informa-
              tion for the file the link references rather than for  the  link
              itself

       -m     fill width with a comma separated list of entries

       -n, --numeric-uid-gid
              like -l, but list numeric UIDs and GIDs

       -N, --literal
              print  raw entry names (don't treat e.g. control characters spe-
              cially)

       -o     like -l, but do not list group information

       -p, --file-type
              append indicator (one of /=@|) to entries

       -q, --hide-control-chars
              print ? instead of non graphic characters

       --show-control-chars
              show non graphic characters as-is  (default  unless  program  is
              `ls' and output is a terminal)

       -Q, --quote-name
              enclose entry names in double quotes

       --quoting-style=WORD
              use  quoting style WORD for entry names: literal, locale, shell,
              shell-always, c, escape

       -r, --reverse
              reverse order while sorting

       -R, --recursive
              list subdirectories recursively

       -s, --size
              print size of each file, in blocks

       -S     sort by file size

       --sort=WORD
              extension -X, none -U, size -S, time -t, version -v

              status -c, time -t, atime -u, access -u, use -u

       --time=WORD
              show time as WORD instead of modification time:  atime,  access,


像这样我应该看哪一行才知道头文件,,英文不是很行 ?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表