Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [posix]

POSIX is an acronym for Portable Operating System Interface, a set of standards defining programming APIs and utility behavior for Unix-like operating systems.

Filter by
Sorted by
Tagged with
3 votes
1 answer
53 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 ...
user avatar
  • 179
3 votes
2 answers
438 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 ...
user avatar
  • 179
3 votes
3 answers
94 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 ...
user avatar
  • 179
5 votes
0 answers
65 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 ...
user avatar
3 votes
2 answers
55 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 ...
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. ...
user avatar
  • 161
1 vote
2 answers
98 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 ...
user avatar
  • 1
3 votes
2 answers
113 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
50 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?&...
user avatar
  • 882
1 vote
2 answers
68 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 "...
user avatar
3 votes
1 answer
72 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 ...
user avatar
  • 854
3 votes
2 answers
78 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 ...
user avatar
1 vote
2 answers
59 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 ...
user avatar
  • 2,897
6 votes
3 answers
698 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) ...
user avatar
  • 2,897
2 votes
0 answers
50 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 ...
user avatar
  • 2,897
3 votes
1 answer
119 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 ...
user avatar
  • 854
3 votes
3 answers
285 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 ...
user avatar
  • 258
4 votes
1 answer
111 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! ...
user avatar
  • 333
4 votes
2 answers
337 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 ...
user avatar
  • 135
0 votes
1 answer
53 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 ...
user avatar
5 votes
2 answers
137 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 ...
user avatar
2 votes
1 answer
77 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, ...
user avatar
1 vote
2 answers
817 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 ...
user avatar
  • 497
1 vote
0 answers
28 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 ...
user avatar
  • 854
3 votes
1 answer
98 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. ...
user avatar
  • 854
1 vote
0 answers
42 views

sudoedit_enhanced written POSIX-ly (readlink possible problem?)

sudoedit_enhanced written POSIX-ly challenge While creating sudoedit_enhanced POSIX (apart from ...
user avatar
2 votes
1 answer
189 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 ...
user avatar
13 votes
4 answers
1k views

Light task-processing systems with zero dependency for Linux systems

I made a prototype for a task processing systems. Architecture Worker - is a entity that is processing one-by-one tasks for the same processor. Processor - (also: executable, app) executable file (...
user avatar
  • 273
1 vote
2 answers
125 views

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

This is the second iteration of this question A note to start with: the first iteration of this question can be found here: Editing system files in Linux (as root) with GUI and CLI text editors As ...
user avatar
0 votes
3 answers
107 views

Safer & simpler allocation functions and macros

I wrote a bunch of functions and macros for safer and simpler allocation. They are documented in their files. Disclaimer: The library requires POSIX extensions, GCC extensions, and LIBBSD ...
user avatar
  • 1,858
4 votes
2 answers
111 views

Generic circular doubly-linked list v2

I've improved, with help of the answers and comments, the linked list that I posted yesterday. It's been through a lot of changes, and is much more useful and safe now. I documented the linked list ...
user avatar
  • 1,858
2 votes
0 answers
34 views

Bash script to scp specific, most-recent files from remote server

I'm writing a helper script that I wish to be able to share with my co-workers. We all work using macOS Mojave, but all have their own shell configurations. For example, I actually use ZSH and bash 5....
user avatar
  • 225
12 votes
3 answers
2k views

Correctly applying the "rule of five" to a RAII socket wrapper

I was trying to create a simple RAII wrapper with rule of 5 for a TCP POSIX socket. My aim was to try learn how to apply rule of five in different situations, but this one was somehow tricky. ...
user avatar
  • 285
6 votes
1 answer
75 views

POSIX+ implementations of echo(1)

Ever wanted a strictly conformant echo(1) implementation on your system? Wait no more: I've built it! What is it? My first large-ish body of C code in a while. ...
user avatar
8 votes
1 answer
337 views

Console arkanoid in C

On an Internet forum a person came with their homework, to write Arkanoid in a console - it seemed they wanted someone to do their homework for them so I did not respond. However, I found the task ...
user avatar
  • 571
9 votes
1 answer
548 views

Custom malloc implementation

I have a malloc() implementation that relies purely on mmap. I'm fairly sure that it doesn't overwrite any of the internal ...
user avatar
  • 1,705
1 vote
1 answer
110 views

Bash Code to backup the history file in Linux [closed]

How is the logic, efficiency and can it be improved? This is a snippet from my .bashrc file, I just wrote it. The code is supposed to do this: Backup my ...
user avatar
3 votes
2 answers
157 views

POSIX shell function for asking questions

I've written a tiny function for asking questions intended for my POSIX shell scripts, where I often need user input. The function takes 2+ arguments, where: Is a string containing the question. , 3....
user avatar
3 votes
1 answer
96 views

batch add users to nextcloud on docker with csv

I have a working script that will batch add users to an instance of nextcloud running on top of docker. This version is the result of changes made after asking this question. I guess I'm looking for ...
user avatar
  • 183
2 votes
1 answer
107 views

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

My intention is to POSIX-ly write one generalized function for running various text editors I use for different purposes through sudoedit, i.e. editing files as ...
user avatar
3 votes
1 answer
28 views

Is device mounted? Both UUID and device names accepted

I am trying to write is_device_mounted script, which in turn will serve a greater purpose in my home Linux system. It does not even have an error reporting ...
user avatar
2 votes
1 answer
274 views

C Recursive Opendir Wrapper to Sort Directories First (ascending/descending)

A recent post on StackOverflow about a recursive directory listing which produced an unsorted mixed file/directory list, sparked the stray thought of "What would it take to write a wrapper for the ...
user avatar
2 votes
2 answers
75 views

Lock file and interrupt signals in POSIX shell script running indefinitely

This script is running indefinitely as the Linux background process. I have put an enormous effort to make this POSIX shell script containing an infinite loop shut down tidily along with the ...
user avatar
2 votes
2 answers
43 views

POSIX-ly finding a specific Java process

In this code I find a list all of the running java processes and give the below function a name to look for, it will do its best. But since I find my approach a ...
user avatar
3 votes
1 answer
91 views

Easy to use code preparation script for CodeReview questions

We all face questions that forget to include their code. Sometimes all of it, sometimes only parts, that make the rest of the question unfortunately incomplete and therefore off-topic. What if it was ...
user avatar
  • 18.8k
1 vote
1 answer
257 views

Detecting the total amount of RAM installed on a hardware from a Linux system using a POSIX shell script

Today, I gave myself a small task of detecting the total amount of RAM installed on a hardware from a Linux system using a POSIX shell script. I ended up using ...
user avatar
0 votes
1 answer
45 views

Shell POSIX OpenSSL file decryption script follow-up #3 (final)

From original very simplistic code: Shell POSIX OpenSSL file decryption script I learned a lot both from the first follow-up review, and the second one as well, many thanks! I just need one final ...
user avatar
0 votes
1 answer
58 views

Shell POSIX OpenSSL file decryption script follow-up #2

This question is the second follow-up of: Shell POSIX OpenSSL file decryption script The first follow-up was: Shell POSIX OpenSSL file decryption script follow-up #1 Both of which have proven very ...
user avatar
26 votes
6 answers
13k views

Create a C style char** from a C++ vector<string>

I am dealing with some older C style APIs, like Posix execve that take a char**. In the rest of my code, I prefer to use a ...
user avatar
3 votes
2 answers
221 views

Generic error handler function for POSIX shell scripts

Intention I came with the idea of generic, portable, highly reliable, and further customizable function for Shell scripts, written in POSIX, for error handling. Purpose The function shall find out, ...
user avatar