Exemplo básico do comando cp
Publicado por euteste da silva (última atualização em 15/07/2010)
[ Hits: 9.150 ]
Exemplo do comando cp utilizando funções de baixo nível. Este programa copia um arquivo de até 1024 bytes.
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#define BUFSIZE 1024
#define MODO_CRIACAO S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
int main(int argc, char *argv[]) {
int fd1, fd2;
char buffer[BUFSIZE];
int bytes_lidos;
if(argc != 3){
fprintf(stderr,"Uso: %s <arquivo> <novo-arquivo>\n",argv[0]);
exit(-1);
}
if((fd1 = open(argv[1],O_RDONLY, S_IREAD))==-1){
fprintf(stderr,"Erro: %s\n",strerror(errno));
exit(-1);
}
if((fd2 = open(argv[2],O_WRONLY | O_TRUNC | O_CREAT, MODO_CRIACAO))==-1){
fprintf(stderr,"Erro: %s\n",strerror(errno));
exit(-1);
}
while((bytes_lidos=read(fd1,buffer,BUFSIZE))!=0)
write(fd2,buffer,bytes_lidos);
close(fd1);
close(fd2);
return(0);
}
Programa CONSULTA/ PESQUISA/ ADICIONA/ EXCLUI registros em arquivos
Editar o arquivo /etc/rc.d/rc.local
Ajustando o sincronismo da legenda com o filme
Trabalhando Nativamente com Logs no Linux
Jogando Daikatana (Steam) com Patch 1.3 via Luxtorpeda no Linux
LazyDocker – Interface de Usuário em Tempo Real para o Docker
Linux Mint: Zram + Swapfile em Btrfs
O widget do Plasma 6 Área de Notificação
Pendrive do Ubuntu 24.04 travando ao tentar fazer a instalação dual bo... (1)
Instalar Dual Boot, Linux+Windows. (13)
tentei instalar o steam pelo terminal, agora ele não abre (3)









