View Full Version : Writing a new helper function
bsd_newbie
February 4th, 2009, 00:48
Suppose I have a helper function f() that is called from main().
In f() I return 0 on success. What value shoudl I return on error 1 or -1. What is BSD convention ?
Thanks.
bsd_newbie
kamikaze
February 4th, 2009, 07:41
You normally assign different numbers for different errors. And most people simply use 1, 2, 3, .... You should document what each number means. -1 will simply be read 255, because the shell only expects an unsigned byte.
This is from one of my manual pages:
EXIT CODES
1 An unknown parameter has been supplied.
2 An unknown mode command has been supplied.
3 More than one mode commands have been supplied.
Often return values are documented with symbolic names. This is good for C-coders, but it's an annoyance in shell-scripting.
trev
February 4th, 2009, 10:14
Suppose I have a helper function f() that is called from main().
In f() I return 0 on success. What value shoudl I return on error 1 or -1. What is BSD convention ?
From <stdlib.h>
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
Mel_Flynn
February 11th, 2009, 18:22
Also check <sysexits.h>.
I personally include this header, then use my own exit status macros like:
#define EX_MYPROGBARFED EX__MAX+1
#define EX_MYPROGDIDABOOBOO EX__MAX+2
etc.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.