Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setprogname in Linux

In Unix I know that there are functions setprogname and getprogname. Both are for setting and getting the program name respectively. They are found in stdlib. I was wondering if Linux has these functions built in as well because I cannot get them to run on the Linux machine (Ubuntu 10.04). Are these functions available? The code is below in case the man pages I found online didn't tell the whole story and I didn't add something that I needed. Thanks!

#define _XOPEN_SOURCE 500

#include<sys/stat.h>
#include<sys/types.h>

#include<errno.h>
#include<fcntl.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>

int main (int argc, char *argv[])
{
    setprogname(argv[0]);
}
like image 217
tpar44 Avatar asked Jun 27 '26 23:06

tpar44


1 Answers

From the *BSD man page about {set,get}progname :

The getprogname() and setprogname() functions manipulate the name of the current program. They are used by error-reporting routines to produce consistent output.

If you want to customize the program name for error reporting with error and error_at_line you can declare and set error_print_progname variable as described in the glibc manual :

As mentioned above the error and error_at_line functions can be customized by defining a variable named error_print_progname.

— Variable: void (*) error_print_progname (void) If the error_print_progname variable is defined to a non-zero value the function pointed to is called by error or error_at_line. It is expected to print the program name or do something similarly useful.

The function is expected to be print to the stderr stream and must be able to handle whatever orientation the stream has.

The variable is global and shared by all threads.

Edit: I just check the gnulib manual about {set,get}progname and error_print_progname :

This variable is missing on all non-glibc platforms: MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11 2011-11, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS.

like image 136
Kwariz Avatar answered Jun 30 '26 15:06

Kwariz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!