需要的API:用于复制文件和查找磁盘使用情况 [英] Needed APIs: For copying file and finding Disk Usage

查看:70
本文介绍了需要的API:用于复制文件和查找磁盘使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我在Linux上编程,其中我需要知道一些

的东西。


1)是否存在可以将文件复制到另一个文件的API(API

相当于''cp'')?

2)是否有API告诉我磁盘使用量(相当于

cmdline

''du'')?

任何指针都将不胜感激。

谢谢你

Dear all,
I am programming in Linux , wherein I need to know a couple of
things.

1) Does an API exist that can copy file onto another file ( an API
equivalent of ''cp'') ?
2) Is there an API that tells me the disk usage ( equivalent for
cmdline
''du'' ) ?
Any pointers would be greatly appreciated.
Thanks n

推荐答案

Sankar写道:
Sankar wrote:

亲爱的所有,

我在Linux上编程,其中我需要知道几件

的东西。


1)是否存在可以将文件复制到另一个文件的API(一个API

相当于''cp'')?


2)是否有API告诉我磁盘使用量(相当于

cmdline

''du'')?


任何指针都会非常感激。
Dear all,
I am programming in Linux , wherein I need to know a couple of
things.

1) Does an API exist that can copy file onto another file ( an API
equivalent of ''cp'') ?

2) Is there an API that tells me the disk usage ( equivalent for
cmdline
''du'' ) ?

Any pointers would be greatly appreciated.



请尝试发布到comp.os.linux。* comp.unix.programmer等。


另请参阅链接下面试图找到你想要的东西:

< http://www.gnu.org/software/libc/manual/html_node/index.html>

Please try posting to comp.os.linux.* comp.unix.programmer etc.

Also see the link below to try to find what you want:
<http://www.gnu.org/software/libc/manual/html_node/index.html>


On Mon,04 Dec 2006 18:01:09 -0800,Sankar写道:
On Mon, 04 Dec 2006 18:01:09 -0800, Sankar wrote:

亲爱的,

我在Linux上编程,其中我需要知道一些

的东西。


1)是否存在可以复制文件的API到另一个文件(一个API

相当于''cp'')?
Dear all,
I am programming in Linux , wherein I need to know a couple of
things.

1) Does an API exist that can copy file onto another file ( an API
equivalent of ''cp'') ?



我认为以下任何ISO C标准都不能保证以下工作,

本身(尽管它'''很难确切地看出你在问什么),但是在Unix平台/实现(包括Linux)领域内的b $ b

未指定的部分是指定和实现的:


#include< stdio.h>

/ * FILE fopen(3)fread(3)fwrite(3)feof(3)fflush( 3)* /


#include< stdlib.h>

/ * EXIT_FAILURE exit(3)* /


int main(void){


FILE * src,* dst;

unsigned char buf [1024];

size_t n;


if(0 ==(src = fopen(" / path / to / source / file"," r")))

perror(fopen),退出(EXIT_FAILURE);


if(0 ==(dst = fopen(" / path / to / sink / file",) w)))

perror(fopen),退出(EXIT_FAILURE);


while(0< (n = fread(buf,1,sizeof buf,src))){

if(n!= fwrite(buf,1,n,dst))

perror (" fwrite"),退出(EXIT_FAILURE);

}


if(!feof(src))

perror (fread),退出(EXIT_FAILURE);


if(0!= fflush(dst))

perror(" fflush"),退出(EXIT_FAILURE);


返回0;


}

The following isn''t guaranteed, I believe, by any ISO C standard to work,
per se (though it''s difficult to discern exactly what you''re asking), but
within the domain of Unix platforms/implementations (including Linux) the
unspecified parts are specified and implemented so:

#include <stdio.h>
/* FILE fopen(3) fread(3) fwrite(3) feof(3) fflush(3) */

#include <stdlib.h>
/* EXIT_FAILURE exit(3) */

int main(void) {

FILE *src, *dst;
unsigned char buf[1024];
size_t n;

if (0 == (src = fopen("/path/to/source/file", "r")))
perror("fopen"), exit(EXIT_FAILURE);

if (0 == (dst = fopen("/path/to/sink/file", "w")))
perror("fopen"), exit(EXIT_FAILURE);

while (0 < (n = fread(buf, 1, sizeof buf, src))) {
if (n != fwrite(buf, 1, n, dst))
perror("fwrite"), exit(EXIT_FAILURE);
}

if (!feof(src))
perror("fread"), exit(EXIT_FAILURE);

if (0 != fflush(dst))
perror("fflush"), exit(EXIT_FAILURE);

return 0;

}


>

2)是否有API告诉我磁盘使用情况(相当于cmdline

''du'')?
>
2) Is there an API that tells me the disk usage ( equivalent for cmdline
''du'' ) ?



您需要在特定于Linux的论坛中提问。


- 比尔

You need to ask in a Linux-specific forum.

- Bill


Sankar写道:
Sankar wrote:

>
>



.... snip ...

.... snip ...


>

1)是否存在可以将文件复制到另一个文件的API(一个API

相当于''cp'')?
>
1) Does an API exist that can copy file onto another file ( an API
equivalent of ''cp'') ?



#include< stdio.h>

int main(void){

int ch;

while(EOF!=(ch = getchar()))putchar(ch);

返回0;

}


将stdin复制到stdout。

#include <stdio.h>
int main(void) {
int ch;
while (EOF != (ch = getchar())) putchar(ch);
return 0;
}

copies stdin to stdout.


2)是否有API告诉我磁盘使用情况(相当于

cmdline''du'')?
2) Is there an API that tells me the disk usage ( equivalent for
cmdline ''du'' ) ?



编号标准C对磁盘或其使用一无所知。


-

Chuck F(cinefalconer at maineline dot net)

可用于咨询/临时嵌入式和系统。

< http://cbfalconer.home.att.net>

No. Standard C knows nothing about disks or the usage thereof.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>


这篇关于需要的API:用于复制文件和查找磁盘使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆