Files
2026-06-25 00:09:09 +08:00

32 lines
849 B
C++

#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
int main(int argc, char **argv) {
int fd1 = open(argv[1], O_RDONLY);
int fd2 = open(argv[2], O_RDWR | O_CREAT, 0666);
int flength = lseek(fd1, 0, SEEK_END);
write(fd1, "\0", 1);
lseek(fd1, 0, SEEK_SET);
char *mapped_mem = (char *)mmap(NULL, flength, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd1, 0);
char *p = mapped_mem;
for (int i = 0; i <= flength; i++) {
if (*p >= 'a' && *p <= 'z')
*p = toupper(*p);
p++;
}
p = mapped_mem + flength;
for (int i = flength; i >= 0; i--) {
write(fd2, p, 1);
p--;
}
printf("%s\n", mapped_mem);
munmap(mapped_mem, flength + 1);
close(fd1);
close(fd2);
return 0;
}