Skip to content
Advertisement

Tag: file

Close file in C

Under Linux I use this code to redirect stdout and stderr on a file, as shown in the code the file is opened using fopen(f) and is it closed using close(fd). My question is whether the close(fd) statement closes all file descriptors, or is it necessary to use fclose(f) as well ? Answer The rule is to close the outermost

Protecting against Time-of-check to time-of-use?

I was reading: https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use They showed this code to be buggy and I totally understand why it’s so: But the real question is how to protect against this type of exploits? Answer You can use the O_NOFOLLOW flag. It will cause the open to fail if basename of the path is a symbolic link. That would solve the described attack.

Quickly create an uncompressible large file on a Linux system

On a Linux system, I need to create a large file (about 10GB), uncompressible file. This file is supposed to reside in a Docker image, needed to test performance in transferring and storing large docker images on a local registry. Therefore, I need the image to be “intrinsically” large (that is: uncompressible), in order to bypass optimization mechanisms. fallocate (described

My file doesn’t return the magic file message

I have to create a magic file that can detect a result of 42 on the 42nd byte. I’ve created the following line to then compile but when I run file -m <file_name> with this content I get the message Answer Your magic should be like this: Here’s my test:

Copy a file from one directory to another in C++

I am writing a C++ program to copy one file from one directory to another. I don’t want to use C++ 17 features. I have already implemented this in the following code. I am on Linux and I want to use the OS cp command to do this. I have written this code. The error is: cp: source: No such

Advertisement