Questions tagged [c]
C is a general-purpose computer programming language used for operating systems, games and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.
881 questions
0 votes
1 answer
87 views
Do posix functions like getpeername or getsockname completely rewrite their buffers?
I am new to socket programming & I have realized that most posix functions from libc require that you pass a buffer & a length. While I can understand this helps the functions to understand ...
1 vote
1 answer
48 views
Do I need to define an absolute path to be able to compile the DRM / Panfrost subtree code of JSM on the RockPro64 / Khadas Edge-V / RK3399?
I'm trying to compile the drm-subtree of JSM because I want to enable the panfrost driver on the RockPro64 / KHADAS EDGE-V / RK3399. The code is here: https://github.com/jsm222/drm-subtree He improved ...
2 votes
1 answer
173 views
Bash exception handling with a stack trace and cleanup code - how to implement?
When using the set -e flag in Bash, then it's difficult to get user-friendly error messages (a stack trace) and it's difficult to add cleanup code that executes before your script exits with an error ...
0 votes
1 answer
177 views
In one process, any way to know whether there exists any other same program is running? [duplicate]
So I am designing a feature to redirect log file if there are multiple processes of this very program are running. I guess this requires me to somehow get to know whether there exists yet unfinished ...
1 vote
1 answer
149 views
If fprinting to stderr fails, which error code should a C program return? [closed]
Assume the following C snippet showing a piece of error handling: #include <sysexits.h> #include <stdio.h> … int main(int argc, char argv*[]) { int retval=0; … if(3!=argc) { /* wrong ...
26 votes
3 answers
2k views
Why does gmtime() give days 1-31, but months 0-11?
The 'gmtime()' standard library function returns a struct that has days numbered 1-31, but months numbered 0-11. Why is that? Presumably there is some historic reason?
7 votes
1 answer
576 views
Syscalls required by glibc calls
Are there any lists compiled that provide a list of linux system calls used per function in a standard glibc build? For example, free() requires mmap, munmap, mprotect, prlimit64, and brk. If ...
2 votes
2 answers
154 views
Sudo doesn't work in my C wrapper
I’m trying to write a C wrapper to run a bash process. The goal of this wrapper is to apply a seccomp policy to restrict certain syscalls. Here is the code: #define _GNU_SOURCE #include <stdio.h>...
0 votes
0 answers
126 views
Panfrost kernel driver on FreeBSD for rk3566?
We are two FreeBSD lovers and a stubborn system administrators. We are trying to project a phone based on FreeBSD for several months. Emanuel Vadot and Jesper Schmitz Mouridsen have enabled the ...
0 votes
2 answers
160 views
when opening a FIFO for reading+writing, and blocking - how to tell if other side opened for reading or writing?
If I open a fifo for reading+writing in blocking mode: fd = open("foo", "O_RDWR"); Then it blocks until someone on the other end opens it for either reading or writing. But how do ...
0 votes
0 answers
76 views
Window move bound to display area
Trying to move a window by grip-able button. On 2 other window managers, and no manager it works fine. Windows move anywhere you want pass display edge bounds. On GNOME Shell and Mutter(Gala) the ...
0 votes
1 answer
79 views
Failed to register hook to tracepoint of signal_generate in Linux?
I am testing FTRACE in Linux VM (ubuntu 24.04) the kernel is Linux VirtualBox 6.11.0-26-generic. I wrote a kernel module to register a hook (probe) to kernel tracepoint of signal_generate, here is the ...
0 votes
2 answers
100 views
Do race conditions occur during pathname resolution with constant string absolute path literals?
According to The Open Group Base Specifications Issue 8, on the rationale of the open() and openat() functions: The purpose of the openat() function is to enable opening files in directories other ...
0 votes
1 answer
96 views
flock not working between forks on the same fd
I am working on a process that forks several times. To debug it, I am using a debug file for which I open a fd and which stays the same for all child forks. Then I have a function print_debug, that ...
0 votes
0 answers
69 views
Why does there appear to be a discrepancy when trying to programmatically access files associated with different tasks in Linux from kernel space?
As a way to better understand Linux kernel structures, interacting with and pulling information from these (and also getting more experience coding in C), I've been building simple kernel modules to ...