C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
detach.c File Reference

Launch executable, detaching from current process. More...

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
Include dependency graph for detach.c:

Go to the source code of this file.

Macros

#define _(String)
#define bindtextdomain(Package, Directory)
#define N_(String)
#define textdomain(Domain)

Functions

int fork_detach_execvp (char **eargv)
 Fork, set new session ID, close files, and execute detached command.
int main (int argc, char *argv[])
 strip ANSI SGR sequences

Detailed Description

Launch executable, detaching from current process.

Author
Bill Waller Copyright (c) 2025 MIT License billx.nosp@m.wall.nosp@m.er@gm.nosp@m.ail..nosp@m.com
Date
2026-02-09

Definition in file detach.c.

Macro Definition Documentation

◆ _

#define _ ( String)
Value:
Definition cm.h:409

Definition at line 25 of file detach.c.

◆ bindtextdomain

#define bindtextdomain ( Package,
Directory )

Definition at line 28 of file detach.c.

◆ N_

#define N_ ( String)
Value:

Definition at line 26 of file detach.c.

◆ textdomain

#define textdomain ( Domain)

Definition at line 27 of file detach.c.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

strip ANSI SGR sequences

Parameters
argcArgument count (should be 2 for the program name and input file)
argvArgument vector (argv[1] should be the input file name)

This function iterates through the input string, copying characters to the output buffer while skipping over any ANSI escape sequences. It looks for sequences that start with "\033[" and end with "m" or "K", and removes them from the output.

< Buffer to hold the input string read from the file

< Buffer to hold the cleaned output string

Definition at line 75 of file detach.c.

75 {
76 char **eargv = &argv[1];
77
78 if (argc < 2) {
79 fprintf(stderr, _("Usage: %s <command> [args...]\n"), argv[0]);
80 return EXIT_FAILURE;
81 }
82
83 if (fork_detach_execvp(eargv) != 0) {
84 fprintf(stderr, _("Failed to fork and execute command\n"));
85 return EXIT_FAILURE;
86 }
87 return EXIT_SUCCESS;
88}
#define _(String)
Definition detach.c:25
char * eargv[MAXARGS]
Definition futil.c:51
int fork_detach_execvp(char **eargv)
Fork, set new session ID, close files, and execute detached command.
Definition detach.c:41

References fork_detach_execvp().

Here is the call graph for this function: