All Questions
1,979 questions
0
votes
0
answers
44
views
Why is data written to the file even though the buffer is not full when the program finishes? [duplicate]
I expected that without calling fclose(), and with the buffer not being full, nothing would be written to the file. But when the program finishes, the data still appears in the file.
Or the C runtime ...
4
votes
2
answers
106
views
Why does read() in C read input in chunks when there's no user-level buffering?
I'm learning how the POSIX read() function works in C. I understand that read() is considered unbuffered, meaning it doesn't manage any internal buffer like fread() does. But I'm confused by the ...
0
votes
1
answer
97
views
Most efficient way to handle I/O for large files [closed]
I am developing a secure P2P file transfer tool in C which is intended to be used for sending arbitrary-size files from between two machines running the program.
I have been trying to figure out what ...
3
votes
3
answers
170
views
Can non-buffered write return 0?
According to the documentation, write returns either the number of bytes written or -1 in case of an error. It's not clear whether the number of bytes written can be 0 when nbyte is positive. The ...
0
votes
1
answer
90
views
How can I read input from terminal in C without waiting for a newline?
I'm on macOS. How can I read input without waiting for a newline? I want to make an ASCII-based RPG with standard WASD controls, so I need to read multiple characters simultaneously to account for ...
1
vote
2
answers
83
views
Is fwrite() atomic when applied to multiple FILE*, same file descriptor?
using fileno() to get the actual file descriptor of stdout.
using fdopen() to create two different FILE* structure, named a and b.
creating two threads, name A and B, using fwrite() to write some ...
2
votes
1
answer
102
views
Low level I/O in C
I am trying to solve a problem from the K&R C programming book that requires one to write a low level I/O program which reads text from a file and prints it on screen, if no input file is given in ...
1
vote
1
answer
87
views
My C program that works with serial port hangs on read if ran for the second time
I am using Cygwin environment to build my program. Also I use the termius library. Essentially, the program opens the serial port:
fuart = open(device, O_RDWR | O_NOCTTY | O_SYNC);
Then its workflow ...
2
votes
1
answer
83
views
Storing user input into an array and terminating at stopping value without storing that value in C
I know how to write a while loop that reads user input, stores into an array then terminates at the stopping value. However, that stopping value is also stored and I'm not sure how to have it not do ...
0
votes
1
answer
61
views
Asynchronous I/O: Any way to get a report on how many bytes code "thinks" it wrote in an I/O request?
I am trying to write files with a C code using asynchronous I/O (librt and aio.h). The current use case is several threads writing several files simultaneously, but this could change to several ...
0
votes
2
answers
103
views
Will SEEK_SET SEEK_CUR SEEK_END not be 0,1,2 on any C lib?
For whence parameter of fseek (or lseek in POSIX), some languages that calls C lib assume SEEK_SET, SEEK_CUR, SEEK_END are 0,1,2, respectively, such as gfortran, Nim [^py].
[^py]: while Python's seek ...
0
votes
3
answers
101
views
Trying to read txt file line by line in C Language
Basically my input file is in the format:
I 15 3 15 10 10 20
S -5 3 15 82
I -20 80 -4 10
S 4 -20 8
The number of ints in a row can vary, but there is always one char at the beginning of each ...
0
votes
1
answer
99
views
How do I Exit a Process if a Child Fails?
The program I'm working with requires a secondary executable to run (for asset compression). For error handling reasons, I need the return value of the child process. According to the system man page,
...
0
votes
1
answer
153
views
Is it unsafe to use getline() in c to read from stdin?
I know that an incorrect use of scanf() to read user input can lead to undefined behavior and potentially security holes in a program. I've seen many people suggesting that is better to use fgets() ...
3
votes
0
answers
218
views
direct io - How to write an odd-sized file using O_DIRECT on Linux
I am experimenting with ways with which I can write odd-sized files i.e., file size not a multiple of block size(512 bytes) using O_DIRECT. Below are two code snippets, one which uses syscalls(open,...