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.

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.

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 63 of file detach.c.

63 {
64 char **eargv = &argv[1];
65
66 if (argc < 2) {
67 fprintf(stderr, "Usage: %s <command> [args...]\n", argv[0]);
68 return EXIT_FAILURE;
69 }
70
71 if (fork_detach_execvp(eargv) != 0) {
72 fprintf(stderr, "Failed to fork and execute command\n");
73 return EXIT_FAILURE;
74 }
75 return EXIT_SUCCESS;
76}
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:29

References fork_detach_execvp().

Here is the call graph for this function: