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.

learn more… | top users | synonyms

1
vote
0answers
30 views

Why use mmap over fread? [migrated]

Why use mmap as opposed to reading from a filestream in chunks into a byte array? I guess I just never thought about using mmap before. mmap(2) fread(3) // Open the file // Read from the file ...
-2
votes
1answer
31 views

Meaning of '&' in C (here in linux kernel function-like Macros) [on hold]

#define TCP_SKB_CB( __skb ) ((struct tcp_skb_cb *)&((__skb)->cb[0])) What does the & mean in this context?
0
votes
0answers
20 views

Link Speed for wireless connections [migrated]

I am working to implement a benchmarker for wireless connections. How can I determine the link speed in mbps? I am working with C language and Linux system.
1
vote
0answers
9 views

Xlib: resize window containing a pixmap [migrated]

Related to how-to-resize-a-pixmap-with-xlib. As it was concluded in the abovementioned topic, it's impossible to resize a pixmap. What about window, after pixmap is copied into it? In the example ...
0
votes
0answers
17 views

fsync on newly created folder? [migrated]

Can anyone explain why fsync can return EINVAL when I pass folder descriptor in it? There is my code, it is pretty simple: #include <dirent.h> /* Defines DT_* constants */ #include ...
0
votes
0answers
15 views

Any GNU C examples where faccessat() function (or equivalent) is used? [migrated]

In reading IEEE Std 1003.1 (POSIX Base Spec) regarding access(), I came across this note: "The purpose of the faccessat( ) function is to enable the checking of the accessibility of files in ...
0
votes
0answers
10 views

How do I write commands to a ttyACM0 device and obtain the resultant information data using C/C++ [migrated]

I am currently stuck with a task of retrieving data from a decoder that monitors 6 joint positions of a robot arm. This device has a USB interface that runs as a serial CDC device. An ASCII command ...
3
votes
2answers
49 views

When does cat finish reading from a pipe?

Given the following code, why does cat only print the contents of the pipe after I've typed \n or CTRL+D? What are the conditions for cat to actually print what it read? #include <stdio.h> ...
2
votes
1answer
38 views

How can I (easily) map a block device node to the directory it's mounted on?

I need to find (in C or C++) the used space on a filesystem (Linux) when being provided only with the disk block device name and the partition number. For most filesystems I can go: Craft a dev ...
3
votes
1answer
42 views

Memory layout of dynamic loaded/linked library

when loading a shared library in Linux system, what is the memory layout of the shared library? For instance, the original memory layout is the following: +-----------+ |heap(ori) | +-----------+ ...
3
votes
1answer
31 views

Io redirection vs file logging performance c/c++

Is there a performance difference from a latency point of view if we do a regular printf and redirect stdout to a file when running the program ( e.g., ./a.out > log.txt 2>&1 ) vs using fprintf ...
0
votes
1answer
26 views

Can I use LXC library in my c program?

Currently, I am designing a c program that will create multiple container and put different applications into them separately to achieve isolation. Is it possible to leverage LXC library to it? I ...
4
votes
1answer
443 views

Can I write C programs for Linux on OS X?

In case I'm writing a program (of any kind) in C, that is meant to be run on Linux environment, can I write it under OS X? (concurrency wise for example) I'm asking this because I like programming in ...
3
votes
2answers
193 views

The «sh» being launched with execl() becomes a zombie

I am spent whole half a day, but still couldn't figure, why is the dash being launched with execl call just becomes a zombie. Below is a minimal test case — I'm just fork a child, make a duplicate of ...
0
votes
1answer
17 views

What happens to TCP when a write fails to enqueue with the device tx ring?

Lets say the device tx ring is full and you do a normal C non blocking write(fd, buff) to enqueue data in the TCP SND buffer. What happens when this fails? In UDP - the packet would be dropped but ...
1
vote
1answer
20 views

Distributing app with .so files?

I'm trying to make a game in C with SDL and OpenGL. Q: Will my game run on computers without SDL installed if I ship the .so files in my game folder? I mean adding the .so files somewhere in the game ...
4
votes
1answer
341 views

why is “timer_t” defined in “time.h” on Linux but not OS X

While I was reading a C source code files, I found this declarations. (This source code was written for linux system program. This is very important information) #include <time.h> #include ...
1
vote
0answers
61 views

Reading the program header contents of an ELF file

How is it possible to extract loadable program headers individually from ELF files? By examining a binary using readelf one can get output similar to: $ readelf -l helloworld Elf file type is EXEC ...
0
votes
1answer
45 views

introduce a c script in a bash file [closed]

My problem is to recover data keyed in text file in bash. I seek the command that can perform this task and I used sed, awk and even cut but I have not succeeded. One friend of mine suggested to ...
0
votes
1answer
38 views

How do I execute a parted command with a C function?

I would like to execute the Linux command "parted" through a C language function? I am using Linux Ubuntu , eclipse. Thanks!
0
votes
0answers
20 views

How to obtain block device label [duplicate]

I have a tricky problem. I have a block device connected to SLES11, it is present in /proc/partitions but it is not mounted (not present in /proc/mounts). From C code I want to find the block device ...
1
vote
1answer
229 views

Reading the contents of an ELF file (programmatically) [closed]

I am trying to retrieve the contents of an additional section within an ELF binary. At this point, I'm using the following code to retrieve the name of each section: #include <stdio.h> #include ...
0
votes
1answer
30 views

Pulling log messages for a particular log in systemd journal?

I was wondering if it is possible to pull log messages for a particular log with systemd's journal logging. For example, when I open a log in C, openlog('slog', LOG_CONS | LOG_PID, LOG_LOCAL1), to ...
1
vote
1answer
47 views

How to run smartctl as root without switching to root?

I have this C code that runs smartctl command and takes its output: #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int main() { cout << ...
0
votes
1answer
70 views

Trying to make a Universal Makefile

I'm working on my own netfilter module for the first time. According to internet documentation, The simplest module contains the following C code: //'Hello World' kernel module, logs call to ...
1
vote
3answers
89 views

loop test strings to see if input is valid for C program input

For example I have a file filled with some pretty gnarly strings. 12345678900 1111111111111111111111111 ...
0
votes
1answer
191 views

C/C++: Running multiple commands as root

I want to execute commands within my C program. However, I need root priviliges to create some folders. I run the following: system("echo <rootpass> | sudo cd <folder> && make ...
-2
votes
1answer
82 views

how to return file descriptor in c [closed]

I am confusing with this. fp=fopen(filename,mode); what is the value fopen() return to fp. is that value is file descriptor integer? is fp called as stream ? if not how to return a ...
0
votes
1answer
63 views

How to select read/write time and again? [closed]

This program only waits one time and I don't understand why. Actually, I don't think this question should be put on hold as off-topic. #include <stdio.h> #include <sys/types.h> #include ...
2
votes
2answers
64 views

linux setuid does not work

I am learning linux suid,so I have written a small c program with the following content to test it #include<stdio.h> int main(){ system("echo 100 >> test.txt"); return 0; } -rwsr-xr-x 1 ...
0
votes
1answer
1k views

“fatal error: stdio.h : No such file or directory” while compiling a C file [closed]

Trying to compile following code in terminal i got root@debian:/home/mz2/Documentos# LANG=C ./soma.c ./soma.c: line 2: syntax error near unexpected token `(' ./soma.c: line 2: `int soma (int a, int ...
0
votes
0answers
49 views

keyboard still working after calling free_irq(1, NULL);

I'm developing a kernel module which free the IRQ number 1 in order to disable the keyboard in Intel architectures. according to wikipedia the IRQ 1 is used for keyboard. but after building and ...
18
votes
4answers
2k views

How to dump a binary file as a C/C++ string literal?

I have a binary file I would like to include in my C source code (temporarily, for testing purposes) so I would like to obtain the file contents as a C string, something like this: \x01\x02\x03\x04 ...
0
votes
0answers
28 views

how to define the top dir in automake system?

I usually use a typical steps to generate the makefile, and firstly I use the "build.sh init" to generate the configure file, and then I use "configure" to generate the makefile with makefile.am file. ...
0
votes
1answer
772 views

Cabal error: Cannot run c compiled programs

I have an old version of cabal-install so I downloaded cabal-install 1.20 and When installing it errors out. Additional note: ghc 7.8.3 OS: CentOS 6.6 Error: Building network-2.4.2.3... ....... ...
1
vote
1answer
249 views

Cannot find -lgcc

I'm trying to compile my next basic c program after hello-world. This contains two supporting modules. I have Ubuntu running in a VM through VirtualBox on a mac. Everything is up to date but I ...
1
vote
0answers
2k views

Getting “cannot open shared object file: No such file or directory” error while run time

I have successfully compiled the file but now I am getting following errors export LD_LIBRARY_PATH=/opt/mcr/v717/sys/java/jre/glnxa64/jre/lib/amd64/server/:D_LIBRARY_PATH ./invoke ./invoke: error ...
0
votes
1answer
25 views

-fPIC Flag System-wide?

Position Independent Code means that the generated machine code is not dependent on being located at a specific address in order to work. and the jumps are relative. So is it OK to declare -fPIC ...
2
votes
1answer
97 views

How to compile manual files .1

I have .c, .h, and .1 files, how can I compile them together in one executable file. Everything clear with .c and .h files, but I have also .1 as I can see from the content it is used for manual, how ...
1
vote
2answers
120 views

How can I link my C program against the Arb library?

I tried to compile the program Testing Li’s criterion in Ubuntu. However, when I do gcc demo.c, I get the output as, demo.c:2:19: fatal error: fmpcb.h: No such file or directory #include "fmpcb.h" ...
1
vote
1answer
383 views

Linking a static library when compiling a C program

I'm linking *.a file with *.c file, so I have used the following command: gcc abc.c -l ad.a (here abc is the C source file and ad is the static library file) then after executing the following ...
3
votes
1answer
129 views

Read .desktop files programmatically [closed]

I would like to make a C program (GTK) that reads a .desktop file. The only thing I need from the .desktop file is the exec command. Is there something built into GTK that would allow me to interact ...
2
votes
2answers
116 views

assign output of a c program to a shell variable: token error

I have a shell script to run several times a .c program ('switch') which admit 3 input paramenters. I want to run the program 4 times passing values {4,16,32,64}, and for parameters ...
4
votes
2answers
2k views

How to check whether a process is daemon or not?

I have written a small daemon that starts at the boot time and does all the things perfectly like writing in the log file. But I want to know, how can we check whether that process is daemon or not? ...
0
votes
1answer
119 views

Linux [admin] How to test pivot_root?

I want to test the pivot_root command line, which moves the root file system of the current process to the directory put_old and makes new_root the new root file system. ...
1
vote
1answer
33 views

snd_rawmidi_open() waits forever - no error message

I am trying to use ALSA for MIDI purposes in C. My problem is, snd_rawmidi_open() sort of "crashes" (waits forever like a while loop) when using valuable arguments : #include <stdio.h> ...
2
votes
0answers
46 views

Make GNU indent break long comments

Is there a way to convince GNU indent to break long comment and change it to multiline comment? Something like this: // Very long comment, longer than 80 characters. Just imagine that. To this: /* ...
2
votes
2answers
699 views

Linux cannot compile without GCC optimizations; implications? [closed]

One can find several threads on the Internet such as this: http://www.gossamer-threads.com/lists/linux/kernel/972619 where people complain they cannot build Linux with -O0, and are told that this is ...
4
votes
1answer
144 views

How to compile programs on Linux systems when I don't have sudo privileges to install the dev dependencies [duplicate]

How should I go about compiling programs that depend on libraries whose development packages (headers and such) aren't pre-installed on the system when I don't have sudo access? In this particular ...
0
votes
0answers
38 views

Inotify notifies only single change

I set the inotify_add_watch to watch /dev/disks. The entries in this directory are: by-id and by-uuid. When I plug-in a pen-drive, this directory gets added with two more directories: by-path and ...