c

how could I intercept linux sys calls?

Hello ! Besides the LD_PRELOAD trick , and Linux Kernel Modules that replace a certain syscall with one provided by you , is there any possibility to intercept a syscall ( open for example ) , so that it first goes through your function , before it reaches the actual open ? ...

Open-source radix/mtrie implementation in C?

I intend to use RADIX / MTRIE as my preferred data-structure for a routing implementation. I would like to know if there's a decent open source implementation available (apart from freebsd-net) which I can use for my purpose, or do I need to write one myself. ...

pthread_cond_wait versus semaphore

What are the pros / cons of using pthread_cond_wait or using a semaphore ? I am waiting for a state change like this : pthread_mutex_lock(&cam->video_lock); while(cam->status == WAIT_DISPLAY) { pthread_cond_wait(&cam->video_cond, &cam->video_lock); } pthread_mutex_unlock(&cam->video_lock); Using a properly initi...

Execute program from within a C program

How do I run another program from within my C program, I need to be able to write data into STDIN of the programed launched (and maybe read from it's STDOUT) Not sure if this is likley to be a standard C function, but I need the solution to work under Linux. Thanks Simon ...

What is this strange C code format?

What advantage, if any, is provided by formatting C code as follows: while(lock_file(lockdir)==0) { count++; if(count==20) { fprintf(stderr,"Can't lock dir %s\n",lockdir); exit(1); } sleep(3); } if(rmdir(serverdir)!=0) { switch(errno) { case EEXIST: ...

Determine the size of a pipe without calling read()

I need a function called SizeOfPipe() which should return the size of a pipe- I only want to know how much data is in the pipe and not actually read data off the pipe itself. I thought the following code would work fseek (pPipe, 0 , SEEK_END); *pBytes = ftell (pPipe); rewind (pPipe); but fseek dosent work on file descriptors. Anothe...

Why do we use extra expression?

Actually, I'm new at C-programming, so there is the sample from Kernighan & Ritchie's "The C Programming Language": int getline(char s[], int lim) { int c, i; i=0; while (--lim > 0; && (c=getchar()) !=EOF && c !='\n') s[i++] = c; if (c =='\n') s[i++] = c; s[i] = '\0'; return i; } Why do we should check i...

Embed data in a C++ program

I've got a C++ program that uses SQLite. I want to store the SQL queries in a separate file -- a plain-text file, not a source code file -- but embed that file in the executable file like a resource. (This has to run on Linux, so I can't store it as an actual resource as far as I know, though that would be perfect if it were for Windows...

Non-blocking pthread_join

Is there a way of doing a non-blocking pthread_join? Some sort of timed join would be good to. I'll try to clarify the question: I'm coding the shutdown of a multithreaded server. If everything goes as it should all the threads exit by their own, but there's a small chance that a thread gets stuck. In this case it would be convenient ...

Getting actual file name (with proper casing) on Windows

Windows file system is case insensitive. How, given a file/folder name (e.g. "somefile"), I get the actual name of that file/folder (e.g. it should return "SomeFile" if Explorer displays it so)? Some ways I know, all of which seem quite backwards: Given the full path, search for each folder on the path (via FindFirstFile). This gives ...

is there a way for my binary to react to some global hotkeys in linux ?

Is it possible to listen for a certain hotkey ( e.g:Ctrl-I ) and then perform a specific action ? My application is written in C , will only run on Linux , and it doesn't have a GUI . Are there any libraries that help with this kind of task ? EDIT:as an example,amarok has global shortcuts , so for example if you map a combination of key...

unsigned char

In C/C++, what is an unsigned char used for? How is this different from a regular char? ...

Make VS compiler catch signed/unsigned assignments?

The Visual Studio compiler does not seem to warn on signed/unsigned assignments, only on comparisons. For example the code below will generate a warning on the if statement but not the initial assignments. Is there anyway to make it catch these? I'm already at W4 but thought (hoped) there may be another setting somewhere. Thanks, int ...

How to import homepath into c program using gcc

I am using gcc for windows. The OS is windows XP. How do I import the homepath variable into my c program so I can write to c:\%homepath%\desktop? I would like to use something similar to: fd = fopen("C:\%%homepath%%\desktop\helloworld.txt","w"); ...

Computationally efficient three dimensional arrays in C

I am trying to solve numerically a set of partial differential equations in three dimensions. In each of the equations the next value of the unknown in a point depends on the current value of each unknown in the closest points. To write an efficient code I need to keep the points close in the three dimensions close in the (one-dimension...

Compile-time LCM / GCD in C

Does anyone know a mechanism to calculate at compile-time the LCM (Least Common Multiple) and/or GCD (Greatest Common Denominator) of at least two number in C (not C++, I know that template magic is available there)? I generally use GCC and recall that it can calculate certain values at compile-time when all inputs are known (ex: sin, c...

Multithreaded Debugger

GDB has severe issues when debugging with multiple threads (pthreads). Are there any other good multi-threaded debuggers for C/C++ on *nix? ...

Need gcc/g++ working on SCO6

Has anyone found a way to get gcc to build/install on SCO6? With 2.95 and 4.3 I get to the point where it needs to use (2.95) or find (4.3) the assembler and that's where it fails. If anyone has figured this out I would appreciate the info! Thanks ...

Spatial Data Structures in C

I do work in theoretical chemistry on a high performance cluster, often involving molecular dynamics simulations. One of the problems my work addresses involves a static field of N-dimensional (typically N = 2-5) hyper-spheres, that a test particle may collide with. I'm looking to optimize (read: overhaul) the the data structure I use ...

Why can't I convert 'char**' to a 'const char* const*' in C?

The following code snippet (correctly) gives a warning in C and an error in C++ (using gcc & g++ respectively, tested with versions 3.4.5 and 4.2.1; MSVC does not seem to care): char **a; const char** b = a; I can understand and accept this. The C++ solution to this problem is to change b to be a const char * const *, which disallows ...