All Questions
Tagged with portability c
45 questions
3
votes
1
answer
712
views
Cross platform raw input handling in C/C++ for Linux and Windows
For some of my terminal videogames I need to accept input in raw mode, which can be done in Windows by using the nonstandard function getch coming from the header <...
3
votes
2
answers
63
views
Finding the Size of a File in a Portable Manner (revision 2)
This is a follow up to Find the Size of a File in a Portable Manner (revision).
Changes made:
The return value of fseek() and ...
4
votes
2
answers
87
views
Find the Size of a File in a Portable Manner (revision)
This is a follow up to Find the Size of a File in a Portable Manner.
What's new:
The fast version (POSIX stat()) does not change the position indicator of the ...
7
votes
2
answers
721
views
Consolidating GNU C's and C23's attributes
C23 has introduced attribute specifier sequences. Consequently, the header below attempts to conditionally define macros for these sequences (for my own use cases). In cases where a compiler does not ...
2
votes
2
answers
151
views
A small header-only input output library
The library (inspired by stb libraries) attempts to provide some commonly used functions (reading a file into memory, determining the size of a file) that are missing from the C standard library ...
3
votes
2
answers
115
views
Unpacking a byte into 8 bytes, where the LSB of each byte corresponds to a bit of the original byte
I needed to unpack a byte into the LSBs of each byte in an 8-byte integer. After some testing, I derived a surprisingly efficient and elegant solution that uses magic numbers multiplication, though ...
9
votes
3
answers
2k
views
Executing a shell command OS-independently
The goal of the code is to convert a Graphviz DOT file to an SVG file, and it achieves this by creating a child process and executing the "dot" command.
...
13
votes
5
answers
3k
views
Portable old-school filesystem tool
I recently made a tool called mkfh to create a FHS compliant filesystem structure.
I aimed to make it as portable as possible, so I wrote it in C89 and also tried ...
3
votes
3
answers
691
views
Command line calculator in C
This code is an arithmetic parser as is the code in a previous question of mine. However this parser handles floating point arguments and mathematical functions, and handles them without needing to ...
4
votes
1
answer
746
views
Basic recursive descent parser in C
The purpose of this code is to evaluate simple integer expressions that make use of the C arithmetic and bitwise operators while respecting C operator precedence and parenthesis. I wrote this code ...
4
votes
1
answer
182
views
Vectorized 16-bit addition in Standard C
The idea is to add a given 16-bit number N to each element of an array of 16-bit integers of arbitrary length, taking advantage of 64-bit integer types and instructions to perform the additions 4 at a ...
3
votes
1
answer
463
views
Portable integer to/from little endian conversion in C
Integers need to be converted to a byte array of defined endianness to be reliably and consistently saved and transmitted, and converted back to be accurately received and read. The goal is to be as ...
2
votes
1
answer
199
views
Portable noreturn in C/C++ between compilers
I'm writing a C/C++ (intended to also be valid C code) for having a noreturn macro variable as widely portable as possible between C and C++ compilers.
...
0
votes
1
answer
167
views
Line-wise input, EOF handling, and behavioral differences between implementations of getchar
I've implemented a menu system where all input calls ultimately go through io_getline, a function which reads a line of input up to the max buffer size or newline (...
1
vote
1
answer
85
views
Open, writing to, and closing a configuration file, and error checking the process in C
All this does is safely and reliably opens, writes to, and closes the file. Yet there are so many gotos and the code is quite verbose. I am not even sure that all ...
5
votes
1
answer
330
views
Two cross-platform implementations of getline in C
I created my cross-platform implementations of getline function in C.
It takes different arguments and have different return values than 'original' ...
8
votes
4
answers
1k
views
Header file that includes all standard C library headers
The Standard C Library consists of various headers files. Often only a few select ones are needed for given code.
Other times it is simply convenient coding to include them all in a .c file, even if ...
0
votes
1
answer
205
views
Polymorphism and inheritance in C99
In the following code I have created the something like the behavior of inheritance and methods in C99 (without vtable). The code compiles without any warnings even with ...
2
votes
2
answers
173
views
Platform-agnostic windowing library
I am making a C library that abstracts window creation with support for the new Vulkan API under a unified API;
I have a github repository that you can check out.
main.c
...
14
votes
2
answers
3k
views
malloc() and free() for Linux with system calls
I have written an implementation of malloc() and free() for Linux using the sbrk() system ...
3
votes
3
answers
192
views
Safely & portably read a value into a predefined integral type of varying size like mode_t
I need to read a value from a text file and put it into a predefined type, in this particular case mode_t. This typedef can have a variety of types underlying it, ...
1
vote
1
answer
632
views
Galton Board Simulation
This program is written for Windows 7 under MinGW using gcc.
I'm seeking recommendations for improving the program's portability.
...
4
votes
2
answers
25k
views
HTTP request parser in C
I'm implementing a simple HTTP server in C, and this is the first part of it. Basically, it takes a string containing a "raw" HTTP request, and parse it into a ...
5
votes
1
answer
725
views
Modular exponentiation without range restriction
A typical modular exponentiation may be coded using the following algorithm.
...
4
votes
3
answers
945
views
Portable multithreaded matrix multiplication in C
I essentially took this progam, and made it compile and run on Windows too. Also, I incorporated some nice points made by Toby Speight.
matrix.h
...
12
votes
3
answers
27k
views
Endianness conversion in C
I have written a simple C header for converting the endianness of short integers and long integers. It uses the GCC macro ...
4
votes
1
answer
91
views
Secure file system utility functions
For Khronos, I've had to develop these utility functions to help me deal with storing the .wav files. However, they could also be used in a variety of applications....
18
votes
2
answers
539
views
The birth of my intelligent assistant: Khronos
I've done a lot of reworking to this main file recently, in regards to using a new speech recognition engine and integrating the last reviews suggestions. My question before is going to be phrased ...
7
votes
2
answers
2k
views
Portable byte order conversion
I'm trying to improve the portability of a file format converter, specifically to POSIX platforms other than Linux. I'd appreciate a review of the following functions used for converting between ...
6
votes
2
answers
33k
views
Timestamp function with millisecond precision
I want to be able to print timestamps with milliseconds precision and time_t doesn't provide this. I also want the code to be portable, so operating specific ...
0
votes
2
answers
2k
views
BMP writer in C
I recently wrote a BMP writer in C:
bmpWriter.h
...
3
votes
1
answer
104
views
Non-curses pager in C (revision 2)
In this revision (follow-up of this post) I've fixed reading from stdin, and also tried to minimise the damage caused by typing additional characters. You might want to see my original post on this.
<...
7
votes
2
answers
96
views
Pseudoportable C script pattern - follow-up
See the initial/previous iteration.
I have rewritten the script following the answer of @200_success.
Now it looks like this:
...
6
votes
1
answer
88
views
Pseudoportable C script pattern
(See the next iteration.)
From time to time, while working with a command line in *nix family of operating systems, we have to write those scripts doing a rather specific task. Usually we use ...
7
votes
2
answers
85
views
Printing the days of the week for every day this year
@chux pointed out that my attempted solution contained several problems. Since I screwed that up so badly, I figure that I should put my revised solution up for review.
...
2
votes
3
answers
2k
views
Simple and safe file reader for C
As an exercise to improve my coding ability in C, I have attempted to write a simple and safe file reader. I believe this should be portable as well to major platforms (correct me if I'm wrong). For ...
8
votes
2
answers
1k
views
Making multiple copies of a pattern
Here's a function for making multiple copies of a block of memory in another block of memory. It handles the case when the size of the target is smaller than or not a perfect multiple of the source ...
6
votes
2
answers
140
views
Inferring Memory Alignment
The following code is intended to infer the alignment of double.
My questions include:
Is there a better to do this? Either by refining the code or using an ...
10
votes
1
answer
2k
views
Recording audio in C 2.0
I posted my audio recording program to Code Review before, and received a stern review along with the other reviews that caused me to rewrite the entire code base. Here is what I would like reviewed:
...
28
votes
2
answers
42k
views
Windows keylogger in C
I have had this keylogger code for a while now (a few years*), and I figured I would put it up for review. Here is what I would like reviewed (in order):
Portability - right now, this program can ...
5
votes
2
answers
357
views
VLC media player watchdog daemon v6
This question is a follow-up to a previous version of this program, which I wrote because I found it annoying that VLC Media Player (which I love) prevents the screensaver from starting after playback ...
8
votes
1
answer
719
views
VLC media player watchdog daemon
I'm looking for bugs, ways to make it more portable or standardized, improvements of any kind. Seems to do what it is supposed to on my Ubuntu 12.04 PC.
...
17
votes
1
answer
2k
views
Brainfuck-to-C compiler written in C++
This compiler, implemented in C++, takes brainfuck code and produces a valid (but still obfuscated) C program, which in turn can be compiled to a native binary.
Expected usage is as follows:
Build ...
5
votes
1
answer
216
views
Portability and "dark corner" gotchas in this "watchdog" program
The following program is intended to "watchdog" a child process, and all subprocesses the child spawns.
The intended behavior is:
A child process (as specified on the command line) is run in a ...
7
votes
1
answer
685
views
UTF-8 character reader function
You may see full code here (note that the link points to the specific commit).
Language is "clean C" (that is, a subset of C89, C99 and C++98 — it is intended to compile under all of these standards)....