OpenBSD-4.6/gnu/usr.sbin/sendmail/libsm

libsm Overview

libsm Overview


$Sendmail: index.html,v 1.14 2001/02/13 21:21:25 gshapiro Exp $

Introduction

Libsm is a library of generally useful C abstractions. Libsm stands alone; it depends on no other sendmail libraries, and the only sendmail header files it depends on are its own, which reside in ../include/sm.

Contents

Here is the current set of packages:
gen: general definitions
debug: debugging and tracing
assert: assertion handling and aborts
heap: memory allocation
exc: exception handling
rpool: resource pools
cdefs: C language portability macros
io: buffered i/o

Naming Conventions

Some of the symbols defined by libsm come from widely used defacto or dejure standards. Examples include size_t (from the C 89 standard), bool (from the C 99 standard), strerror (from Posix), and __P (from BSD and Linux). In these cases, we use the standard name rather than inventing a new name. We import the name from the appropriate header file when possible, or define it ourselves when necessary. When you are using one of these abstractions, you must include the appropriate libsm header file. For example, when you are using strerror, you must include <sm/string.h> instead of <string.h>.

When we aren't implementing a standard interface, we use a naming convention that attempts to maximize portability across platforms, and minimize conflicts with other libraries. Except for a few seemingly benign exceptions, all names begin with SM_, Sm or sm_.

The ISO C, Posix and Unix standards forbid applications from using names beginning with __ or _[A-Z], and place restrictions on what sorts of names can begin with _[a-z]. Such names are reserved for the compiler and the standard libraries. For this reason, we avoid defining any names that begin with _. For example, all libsm header file idempotency macros have the form SM_FOO_H (no leading _).

Type names begin with SM_ and end with _T. Note that the Posix standard reserves all identifiers ending with _t.

All functions that are capable of raising an exception have names ending in _x, and developers are encouraged to use this convention when writing new code. This naming convention may seem unnecessary at first, but it becomes extremely useful during maintenance, when you are attempting to reason about the correctness of a block of code, and when you are trying to track down exception-related bugs in existing code.

Coding Conventions

The official style for function prototypes in libsm header files is
extern int
foo __P((
	int _firstarg,
	int _secondarg));
The extern is useless, but required for stylistic reasons. The parameter names are optional; if present they are lowercase and begin with _ to avoid namespace conflicts. Each parameter is written on its own line to avoid very long lines.

For each structure struct sm_foo defined by libsm, there is a typedef:

typedef struct sm_foo SM_FOO_T;
and there is a global variable which is defined as follows:
const char SmFooMagic[] = "sm_foo";
The first member of each structure defined by libsm is
const char *sm_magic;
For all instances of struct sm_foo, sm_magic contains SmFooMagic, which points to a unique character string naming the type. It is used for debugging and run time type checking.

Each function with a parameter declared SM_FOO_T *foo contains the following assertion:

SM_REQUIRE_ISA(foo, SmFooMagic);
which is equivalent to
SM_REQUIRE(foo != NULL && foo->sm_magic == SmFooMagic);
When an object of type SM_FOO_T is deallocated, the member sm_magic is set to NULL. That will cause the above assertion to fail if a dangling pointer is used.

Additional Design Goals

Here are some of my design goals:

FileSizeDate
Makefile 822 2007-02-04
README 4532 2004-06-24
assert.c 4247 2004-06-24
assert.html 14201 2001-09-12
b-strcmp.c 3484 2006-03-23
b-strl.c 5125 2006-03-23
cdefs.html 2460 2001-09-12
cf.c 2034 2001-10-02
clock.c 14809 2006-03-23
clrerr.c 882 2001-10-02
config.c 5197 2007-04-05
debug.c 7583 2004-12-16
debug.html 7867 2002-04-18
errstring.c 6385 2004-06-24
exc.c 13400 2007-02-04
exc.html 23833 2007-02-04
fclose.c 3206 2006-03-23
feof.c 971 2001-10-02
ferror.c 942 2001-10-02
fflush.c 3180 2006-03-23
fget.c 2467 2001-10-02
findfp.c 11153 2007-02-04
flags.c 1300 2007-02-04
fopen.c 8528 2006-03-23
fpos.c 3193 2006-03-23
fprintf.c 1391 2001-10-02
fpurge.c 1186 2001-10-02
fput.c 1289 2001-10-02
fread.c 2347 2001-10-02
fscanf.c 1385 2001-10-02
fseek.c 7425 2006-03-23
fvwrite.c 6396 2001-10-02
fvwrite.h 744 2001-09-12
fwalk.c 1455 2001-10-02
fwrite.c 1591 2001-10-02
gen.html 916 2001-09-12
get.c 1153 2001-10-02
glue.h 735 2001-09-12
heap.c 17714 2004-12-16
heap.html 13388 2001-09-12
io.html 27266 2001-09-12
ldap.c 31542 2008-05-05
local.h 9668 2007-02-04
makebuf.c 3500 2002-01-14
match.c 2850 2001-10-02
mbdb.c 16840 2004-06-24
memstat.c 5251 2007-04-05
mpeix.c 14182 2008-05-05
niprop.c 4806 2001-10-02
path.c 400 2001-10-02
put.c 1656 2002-01-14
refill.c 7255 2006-03-23
rewind.c 1111 2001-10-02
rpool.c 11952 2004-12-16
rpool.html 6236 2001-09-12
sem.c 3779 2006-03-23
setvbuf.c 4315 2001-10-02
shm.c 2682 2006-03-23
signal.c 7143 2006-03-23
smstdio.c 6294 2004-12-16
snprintf.c 2352 2007-02-04
sscanf.c 2314 2002-04-18
stdio.c 9964 2006-03-23
strcasecmp.c 3229 2001-10-02
strdup.c 2857 2004-06-24
strerror.c 1347 2001-10-02
strexit.c 2835 2001-10-02
string.c 952 2001-10-02
stringf.c 1818 2001-10-02
strio.c 9443 2006-03-23
strl.c 7712 2002-04-18
strrevcmp.c 1659 2001-10-02
strto.c 5583 2002-01-14
syslogio.c 4229 2001-10-02
t-cf.c 944 2001-10-02
t-event.c 1861 2006-03-23
t-exc.c 2837 2001-10-02
t-float.c 1833 2001-10-02
t-fopen.c 878 2002-04-18
t-heap.c 1377 2001-10-02
t-match.c 1136 2001-10-02
t-memstat.c 2117 2007-04-05
t-path.c 752 2001-10-02
t-qic.c 5560 2007-02-04
t-rpool.c 1547 2001-10-02
t-scanf.c 1442 2002-01-14
t-sem.c 5266 2007-04-05
t-shm.c 4533 2005-04-09
t-smstdio.c 1596 2001-10-02
t-string.c 978 2001-10-02
t-strio.c 785 2001-10-02
t-strl.c 3624 2001-10-02
t-strrevcmp.c 1004 2001-10-02
t-types.c 2772 2002-04-18
test.c 2796 2002-01-14
ungetc.c 4029 2006-03-23
util.c 4572 2007-02-04
vasprintf.c 2984 2004-06-24
vfprintf.c 24719 2006-08-13
vfscanf.c 19233 2007-02-04
vprintf.c 1009 2001-10-02
vsnprintf.c 1921 2001-10-02
wbuf.c 2580 2001-10-02
wsetup.c 1934 2002-04-18
xtrap.c 663 2001-10-02