at是將文本連接起來的程序,將第二個及以後的文件存到第一個裏
#include <stdio.h>
#include <fcntl.h>
void filecopy(int fdin, int fdout)
{
char c;
while( read(fdin, &c, 1) == 1 ) {
write(fdout, &c, 1);
}
}
int main( int argc, char *argv[] )
{
int fdin, fdout;
if((fdin = open(*++argv, O_RDONLY, 0)) == -1) {
write( 2, "ERROR :Can't open", 17);
write( 2, *argv, sizeof( *argv ));
}
if( argc == 1 ) {
filecopy( 0, 1 );
} else {
while( --argc );
}
if( (fdout = open(*++argv, O_WRONLY, 0)) == -1 ) {
write( 2, "ERROR :", 7);
write( 2, *argv, 20);
} else {
filecopy(fdin, fdout);
}
return 0;
}