Exemplo básico do comando cp
Publicado por euteste da silva (última atualização em 15/07/2010)
[ Hits: 8.957 ]
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); }
Gerenciamento de alunos com dados armazenados em arquivo
Como aprovar Pull Requests em seu repositório Github via linha de comando
Como gerar um podcast a partir de um livro em PDF
Automatizando digitação de códigos 2FA no browser
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Como Definir o Painel Principal em Múltiplos Monitores no Linux Mint
Minecraft Launcher para Arch Linux
Instalar o Apache, MySQL e PHP no Oracle Linux 8
Resolvendo o erro "libQt6Widgets.so.6: cannot open shared object file" no Linux
Mouse bluetooth no Debian 12.10. (0)
Mouse bluetooth no Debian 12.10. (0)
tentando instalar em um notebook antigo o Linux LegacyOS_2023... (2)