Skip to main content

Questions tagged [posix]

Use this tag for code that is intended to be work on any system conforming to POSIX specifications.

Filter by
Sorted by
Tagged with
3 votes
3 answers
338 views

Append Buffer for Buffering Small write(2) Calls

The purpose of this is written in the comment below (it is meant to be used in a text editor): abuf.h: ...
Harith's user avatar
  • 8,704
2 votes
1 answer
40 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 ...
Harith's user avatar
  • 8,704
4 votes
2 answers
77 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 ...
Harith's user avatar
  • 8,704
4 votes
1 answer
176 views

Find the Size of a File in a Portable Manner

There's no function in the Standard C Library to determine the size of a file. The POSIX Standard has stat()/fstat() which are ...
Harith's user avatar
  • 8,704
5 votes
1 answer
185 views

Parsing command-line arguments with getopt in C++

I did not find anything to parse command-line arguments in C++ (which was surprising), so I fell back to getopt() which has served me well in C (I am currently not ...
Harith's user avatar
  • 8,704
9 votes
4 answers
2k views

Implementing a simple byte manipulation encryption

Can you kindly take a look at the code? Any suggestions regarding performance, readability, potential bugs, portability, security measures, etc. are highly appreciated. The code reads a character, a ...
user174174's user avatar
7 votes
7 answers
404 views

A simple shell in C

The M-Shell (msh) provides a basic command-line interface similar, and features some builtins (cd, exit, help, whoami, kill). ...
Harith's user avatar
  • 8,704
0 votes
1 answer
27 views

Yet another sh script to backup one directory

A single directory should simply be backed up with the zip tool, and the time of the backup should be preserved in the file name. I have written a Posix shell script for this. Can this script simply ...
Tobias Grothe's user avatar
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 ...
Labricecat's user avatar
1 vote
2 answers
70 views

Script to prevent nested root shells (POSIX)

Script to prevent nested root shells shall do exactly as said, plus some niceties like an error message when someone runs it with some argument/option. ...
Vlastimil Burián's user avatar
2 votes
2 answers
147 views

Wait for child while polling file descriptor with self-pipe controlled by different threads

I am working on a personal project, and one of the things it does is to call a blocking operation on a file descriptor while a forked+exec'ed child process is running. It needs to know when the ...
Seninha's user avatar
  • 171
4 votes
3 answers
393 views

Implementation of pthread multithreading and mutex

I am trying to implement a "proper" pthread multithreading program with pthread mutex. I want it to be as C-standard-conforming and POSIX-conforming as possible. The below is my ...
D.J. Elkind's user avatar
7 votes
2 answers
3k views

Proper implementation of signal handler and multithreading (pthread)

I am trying to implement a "proper" signal handler that works correctly for multiple threads, and to be as C-standard-conforming and POSIX-conforming as possible. The below is my ...
D.J. Elkind's user avatar
8 votes
4 answers
1k views

Run command in a child process

Inspired by this answer from SO, I try to find a version of fork()/exec()/wait() which: starts a child process; catches stdout, stderr and return code separately; properly handles all possible errors ...
D.J. Elkind's user avatar
0 votes
1 answer
42 views

Printing script intro by typing Y/y or just by pressing Enter in a POSIX shell script

Say, I have my POSIX script introduction stored in variable: ...
Vlastimil Burián's user avatar
3 votes
3 answers
138 views

Follow up: A chat server using the select() API

This is a follow up to my last question: Multiperson chat server using the select() API Changes: After much fine critique, I made the following changes to the code: Removed redundant casts and ...
Harith's user avatar
  • 8,704
11 votes
2 answers
1k views

Multiperson chat server using the select() API

I followed the Beej's Guide to Network Programming. The program acts like a multi-user chat server. One connects and sends a message to the server, which is forwarded to all that are connected. There'...
Harith's user avatar
  • 8,704
3 votes
1 answer
57 views

Wipe a directory tree

The idea here is to destroy the data in a directory tree by finding any files in it and overwriting their data with garbage before deleting them. The function returns minus the number of errors ...
CPlus's user avatar
  • 928
2 votes
1 answer
33 views

Find first or last argument lexicographically or temporally

I often find I need to find the earliest or latest file matching a given pattern, and sometimes to choose the lowest or highest string from several possibilities. The following four functions provide ...
Toby Speight's user avatar
  • 76.9k
5 votes
2 answers
627 views

RAII POSIX process created by fork

By analogy with std::thread, I've written an RAII POSIX process: ...
jezza's user avatar
  • 205
-3 votes
1 answer
189 views

Opening a directory as a file descriptor creating it if it does not exist [closed]

Variables: conf of type struct Conf whose details are not relevant to this review stores the configuration data being read. <...
user avatar
5 votes
1 answer
3k views

Executing a Bash script from C++

I am trying to execute a Bash command, get the pid, read the (error) output and optionally pass input. I am still quite new at C++ and I would like to know if this is a correct & safe ...
user3876583945's user avatar
3 votes
1 answer
102 views

System V signal API using the standard POSIX API

I wrote a program that implements a POSIX signal API. It implements the functions sigset(), sighold(), ...
Lorand's user avatar
  • 31
4 votes
1 answer
77 views

improved "tee" utility

We have modified the tee program with your suggestions from the previous pull request. Did I implement well? I would like to optimize the program even more, what ...
Mike's user avatar
  • 299
3 votes
2 answers
605 views

Implementation of the "tee" utility program

How can I optimize the program? To make it more optimal? The program should be more optimal in terms of source code, compiled executable size, memory usage, speed, bugs etc. Please criticize the ...
Mike's user avatar
  • 299
3 votes
3 answers
179 views

tee: copy standard input to both stdout and a file

I implemented the tee command from linux. The program also handles the -a option for adding text to the end of a file if it ...
Mike's user avatar
  • 299
5 votes
0 answers
756 views

A POSIX getdelim() and getline() implementation for MSVC

Tired of always having problems in reading arbitrary length lines from file under Windows, I tried to write a POSIX getdelim() and ...
Costantino Grana's user avatar
3 votes
2 answers
139 views

change file attributes on a Linux file system with chattr

I am reading the book The Linux Programming Interface and I have reached the exercise in which the implementation of the chattr command in C is required. I would ...
Dave's user avatar
  • 51
15 votes
2 answers
1k views

A multithreaded implementation of the 'which' command

Here is an implementation of the 'which' command which can tell where programs are located. ...
JohnScott's user avatar
  • 171
1 vote
2 answers
194 views

Function that behaves as dup2

I am reading the book Advanced Programming in the UNIX Environment and I have tried to solve the following exercise: Write a function that performs the same actions as ...
Mark's user avatar
  • 449
3 votes
2 answers
369 views

Retry read/write until all bytes are transferred or error occurs

Currently I have a wrapper function for the read/write system calls, the purpose of which is to eliminate partial transfer ...
user avatar
4 votes
1 answer
55 views

Whose `git` is it anyway?

A Posix function for finding the nearest parent file. For example "what .git/ am I working in?" or "is there an .npmrc affecting npm from this path?&...
psaxton's user avatar
  • 892
1 vote
2 answers
98 views

Editing system files in Linux (as root) with GUI and CLI text editors #3

One year and a half ago I posted the second iteration of this script for a review here: Editing system files in Linux (as root) with GUI and CLI text editors #2 Since then, it has been "...
Vlastimil Burián's user avatar
3 votes
1 answer
154 views

UNIX calendar(1) in C

This is a simple implementation of the calendar(1) utility included in some UNIX systems (all BSDs have it, GNU has not). I do not have much experience with ...
phillbush's user avatar
  • 864
3 votes
2 answers
140 views

Posix signal implementation

My hobby is Unix-like operating systems. Recently I began writing my own sel4-based Posix compliant OS. Here's the code for internal signal handling functions which presents a kind of backend to help ...
Сергей Волкович's user avatar
1 vote
2 answers
1k views

Installing packages if they don't exist in Bash

This script simply installs the chosen packages if they're not present on a Linux system using the apt package manager. Notes on improvements of any aspect are ...
T145's user avatar
  • 3,099
6 votes
3 answers
765 views

Updating text in a HTML document with Bash

This is a small script to update my project's README file. Notes on improvements from any aspect are welcome! Here is the document it updates. readme.sh (Executed like so: ./readme.sh) ...
T145's user avatar
  • 3,099
3 votes
0 answers
77 views

The Blacklist v2

This script gathers domains listed from sources in this JSON file and compiles them into one text file. Text files that have a similar key under the whitelists ...
T145's user avatar
  • 3,099
3 votes
1 answer
173 views

Pomodoro timer daemon in C for BSD systems

I wrote a Pomodoro timer daemon for BSD systems in C (may work on Linux with -lbsd). The server uses poll(2) and sockets to communicate with the client and to ...
phillbush's user avatar
  • 864
3 votes
3 answers
987 views

Efficiently read a file into a (C) string using POSIX APIs

Exactly what the title says, this is a C++ class that attempts to read a file into a null-terminated string as efficiently as possible, using POSIX APIs. Obviously this is not intended to be portable ...
Ray Hamel's user avatar
  • 268
4 votes
1 answer
127 views

Recursively list directories

How does the following look to list the directories on a posix system? This is actually the first piece of C code that I've written where I've actually been able to use for a real-world problem! ...
David542's user avatar
  • 409
4 votes
2 answers
1k views

C++ TcpServer class

I have a class Tcp_Server that implements a TCP server. This is the base class for the other types of servers available in my program. For example ...
Bogdasar's user avatar
  • 135
0 votes
1 answer
67 views

Attempt on basic input validation and functional programming in a POSIX shell

In spite of all the POSIX shell disadvantages, I am still sticking with it and I love its portability. Recently, I was searching for a way of code re-use, which turns out to be structured programming ...
Vlastimil Burián's user avatar
5 votes
2 answers
158 views

Log file name adjustment

I have the following code that takes user input "path" and adds the current time into the filename after the name part and before any extension (if it exists). It seems a little hacky to me ...
Jacob Geigle's user avatar
4 votes
2 answers
134 views

*nix, *bsd, etc basic `tput` color setup

My goal with the below piece of POSIX shell code was to address the more platforms the better with shell tput colors. With this code, I now start all of my scripts, ...
Vlastimil Burián's user avatar
1 vote
2 answers
3k views

Regex to match each line in a file, with windows and/or linux line break included, even for missing line break at EOF

My requirement is to match each line of a text file, including the line terminator of each, at most excluding the terminator of the last line, to take into account the crippled, non POSIX-compiant ...
Enlico's user avatar
  • 537
2 votes
0 answers
37 views

Implementation of GNU shuf(1) now supporting nul characters

Some time ago, I implemented shuf(1), but it had an issue: it ignored nul characters in the input. This new version tries to solve this problem (but uses the ...
phillbush's user avatar
  • 864
3 votes
1 answer
140 views

POSIX + BSD-extensions implementation of shuf(1)

I implemented GNU shuf(1) in C using POSIX system calls and some BSD extensions. You must compile it with -lbsd. ...
phillbush's user avatar
  • 864
1 vote
0 answers
44 views

sudoedit_enhanced written POSIX-ly (readlink possible problem?)

sudoedit_enhanced written POSIX-ly challenge While creating sudoedit_enhanced POSIX (apart from ...
Vlastimil Burián's user avatar
2 votes
1 answer
302 views

POSIX shell function to "dump" all given arguments

My today's idea was to create a POSIX shell function to dump all given arguments, typical use would be to call it from a fucntion, where you already know some arguments are not well set (empty; not ...
Vlastimil Burián's user avatar