[1] | 1 | /* --------------------------------------------------------------
|
---|
| 2 | *
|
---|
| 3 | * The developement of this library has been stimulated by reading
|
---|
| 4 | * a paper on 'Robust Programming' by Matt Bishop, although
|
---|
| 5 | * not all of his ideas might be implemented in the same
|
---|
| 6 | * strictness as discussed in the paper.
|
---|
| 7 | *
|
---|
| 8 | * --------------------------------------------------------------
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #ifndef SL_SLIB_H
|
---|
| 12 | #define SL_SLIB_H
|
---|
| 13 |
|
---|
| 14 | #include <errno.h>
|
---|
| 15 | #include <stdio.h>
|
---|
| 16 | #include <stdlib.h>
|
---|
| 17 | #include <stdarg.h>
|
---|
| 18 | #include <sys/types.h>
|
---|
| 19 |
|
---|
| 20 | #include "config_xor.h"
|
---|
| 21 |
|
---|
| 22 | #ifdef HAVE_UNISTD_H
|
---|
| 23 | #include <unistd.h>
|
---|
| 24 | #endif
|
---|
| 25 |
|
---|
| 26 | /****************
|
---|
| 27 |
|
---|
| 28 | -- Defined in config.h. --
|
---|
| 29 |
|
---|
| 30 | #ifndef _(string)
|
---|
| 31 | #define _(string) string
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
| 34 | #ifndef N_(string)
|
---|
| 35 | #define N_(string) string
|
---|
| 36 | #endif
|
---|
| 37 |
|
---|
| 38 | *****************/
|
---|
| 39 |
|
---|
| 40 | /* --------------------------------------------------------------
|
---|
| 41 | *
|
---|
| 42 | * Typedefs, global variables, macros.
|
---|
| 43 | *
|
---|
| 44 | * --------------------------------------------------------------
|
---|
| 45 | */
|
---|
| 46 |
|
---|
| 47 | extern long int sl_errno; /* Global error variable. */
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | /* The ticketing system; used to hide internals from the
|
---|
| 51 | * programmer.
|
---|
| 52 | */
|
---|
| 53 | typedef long int SL_TICKET; /* Unique ID for opened files. */
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | /*
|
---|
| 57 | * TRUE, FALSE
|
---|
| 58 | */
|
---|
| 59 | #define SL_TRUE 1
|
---|
| 60 | #define SL_FALSE 0
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /*
|
---|
| 65 | * The following macros are provided:
|
---|
| 66 | *
|
---|
| 67 | * SL_ISERROR(x) TRUE if return status of 'x' is an error code.
|
---|
| 68 | * SL_REQUIRE(x, xstr) Abort if 'x' is false.
|
---|
| 69 | * SL_ENTER(s) Trace entry in function 's'.
|
---|
| 70 | * SL_RETURN(x, s) Trace return from function 's'.
|
---|
| 71 | */
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | /*
|
---|
| 75 | * The error codes.
|
---|
| 76 | */
|
---|
| 77 | #define SL_ENONE 0
|
---|
| 78 |
|
---|
| 79 | #define SL_ENULL -1024 /* Invalid use of NULL pointer. */
|
---|
| 80 | #define SL_ERANGE -1025 /* Argument out of range. */
|
---|
| 81 | #define SL_ETRUNC -1026 /* Result truncated. */
|
---|
| 82 | #define SL_EREPEAT -1027 /* Illegal repeated use of function. */
|
---|
| 83 |
|
---|
| 84 | #define SL_EINTERNAL -1028 /* Internal error. */
|
---|
| 85 | #define SL_ETICKET -1029 /* Bad ticket. */
|
---|
| 86 | #define SL_EBADFILE -1030 /* File access error. Check errno. */
|
---|
| 87 | #define SL_EBOGUS -1031 /* Bogus file. */
|
---|
| 88 | #define SL_EMEM -1032 /* Out of memory. */
|
---|
| 89 | #define SL_EUNLINK -1033 /* Unlink error. Check errno. */
|
---|
| 90 | #define SL_EREWIND -1034 /* Rewind error. Check errno. */
|
---|
| 91 | #define SL_EFORWARD -1035 /* Forward error. Check errno. */
|
---|
| 92 | #define SL_EREAD -1036 /* Read error. Check errno. */
|
---|
| 93 | #define SL_EWRITE -1037 /* Write error. Check errno. */
|
---|
| 94 | #define SL_ESYNC -1038 /* Write error. Check errno. */
|
---|
| 95 |
|
---|
| 96 | #define SL_EBADNAME -1040 /* Invalid name. */
|
---|
| 97 | #define SL_ESTAT -1041 /* stat of file failed. Check errno. */
|
---|
| 98 |
|
---|
| 99 | #define SL_EBADUID -1050 /* Owner not trustworthy. */
|
---|
| 100 | #define SL_EBADGID -1051 /* Group writeable and not trustworthy.*/
|
---|
| 101 | #define SL_EBADOTH -1052 /* World writeable. */
|
---|
| 102 |
|
---|
| 103 | #define SL_TOOMANY -1053 /* Too many open files */
|
---|
| 104 | #define SL_TIMEOUT -1054 /* Timeout in read */
|
---|
| 105 | /*
|
---|
| 106 | * All int functions return SL_NONE on success.
|
---|
| 107 | */
|
---|
| 108 |
|
---|
| 109 | #ifdef __cplusplus
|
---|
| 110 | extern "C" {
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|
| 113 | int dlog (int flag, char * file, int line, const char *fmt, ...);
|
---|
| 114 |
|
---|
| 115 | char * sl_get_errmsg();
|
---|
| 116 |
|
---|
| 117 | /* ----------------------------------------------------------------
|
---|
| 118 | *
|
---|
| 119 | * Heap consistency routines
|
---|
| 120 | *
|
---|
| 121 | * ---------------------------------------------------------------- */
|
---|
| 122 |
|
---|
| 123 | int sl_test_heap();
|
---|
| 124 |
|
---|
| 125 | /* ----------------------------------------------------------------
|
---|
| 126 | *
|
---|
| 127 | * Capability routines
|
---|
| 128 | *
|
---|
| 129 | * ---------------------------------------------------------------- */
|
---|
| 130 |
|
---|
| 131 | extern int sl_useCaps;
|
---|
| 132 |
|
---|
| 133 | int sl_drop_cap ();
|
---|
| 134 | int sl_drop_cap_sub();
|
---|
| 135 | int sl_get_cap_sub();
|
---|
| 136 | int sl_drop_cap_qdel();
|
---|
| 137 | int sl_get_cap_qdel();
|
---|
| 138 |
|
---|
| 139 | /* ----------------------------------------------------------------
|
---|
| 140 | *
|
---|
| 141 | * String handling routines
|
---|
| 142 | *
|
---|
| 143 | * ---------------------------------------------------------------- */
|
---|
| 144 |
|
---|
| 145 | /*
|
---|
| 146 | * A memset that does not get optimized away
|
---|
| 147 | */
|
---|
| 148 | void *sl_memset(void *s, int c, size_t n);
|
---|
[11] | 149 | #if !defined(SH_REAL_SET)
|
---|
[1] | 150 | #undef memset
|
---|
| 151 | #define memset sl_memset
|
---|
[11] | 152 | #endif
|
---|
[1] | 153 |
|
---|
| 154 | /*
|
---|
| 155 | * Copy src to dst. siz is the length of dst.
|
---|
| 156 | */
|
---|
| 157 | int sl_strlcpy(char * dst, /*@null@*/const char * src, size_t siz);
|
---|
| 158 |
|
---|
| 159 | /*
|
---|
| 160 | * Append src to dst. siz is the length of dst.
|
---|
| 161 | */
|
---|
| 162 | int sl_strlcat(char * dst, /*@null@*/const char *src, size_t siz);
|
---|
| 163 |
|
---|
| 164 | /*
|
---|
| 165 | * An implementation of vsnprintf. va_start/va_end are in the caller
|
---|
| 166 | * function.
|
---|
| 167 | */
|
---|
| 168 | int sl_vsnprintf(char *str, size_t n,
|
---|
| 169 | const char *format, va_list vl );
|
---|
| 170 |
|
---|
| 171 | /*
|
---|
| 172 | * An implementation of snprintf.
|
---|
| 173 | */
|
---|
| 174 | int sl_snprintf(char *str, size_t n,
|
---|
| 175 | const char *format, ... );
|
---|
| 176 |
|
---|
| 177 | /*
|
---|
| 178 | * A robust drop-in replacement of strncpy. strlcpy is preferable.
|
---|
| 179 | */
|
---|
| 180 | char * sl_strncpy(/*@out@*/char *dst, const char *src, size_t size);
|
---|
| 181 |
|
---|
| 182 | /*
|
---|
| 183 | * Robust strncat.
|
---|
| 184 | */
|
---|
| 185 | char * sl_strncat(char *dst, const char *src, size_t n);
|
---|
| 186 |
|
---|
| 187 | /*
|
---|
| 188 | * strstr
|
---|
| 189 | */
|
---|
| 190 | char * sl_strstr (const char * haystack, const char * needle);
|
---|
| 191 |
|
---|
| 192 | /*
|
---|
| 193 | * robust strncmp replacement
|
---|
| 194 | */
|
---|
| 195 | int sl_strncmp(const char * a, const char * b, size_t n);
|
---|
| 196 |
|
---|
| 197 | /*
|
---|
| 198 | * robust strcmp replacement
|
---|
| 199 | */
|
---|
| 200 | int sl_strcmp(const char * a, const char * b);
|
---|
| 201 |
|
---|
| 202 | /*
|
---|
| 203 | * robust strlen replacement
|
---|
| 204 | */
|
---|
| 205 | #define sl_strlen(arg) ((arg == NULL) ? 0 : (strlen(arg)))
|
---|
| 206 |
|
---|
| 207 | /* ----------------------------------------------------------------
|
---|
| 208 | *
|
---|
| 209 | * Privilege handling routines
|
---|
| 210 | *
|
---|
| 211 | * ---------------------------------------------------------------- */
|
---|
| 212 |
|
---|
| 213 | /*
|
---|
| 214 | * ONE OF THE FOLLOWING THREE FUNCTIONS
|
---|
| 215 | * SHOULD BE CALLED BEFORE ANY OTHER OF THE
|
---|
| 216 | * UID HANDLING FUNCTIONS.
|
---|
| 217 | */
|
---|
| 218 | int sl_policy_get_user(char *username); /* drop SUID to <username> */
|
---|
| 219 | int sl_policy_get_real(char *username); /* drop privs to <username> */
|
---|
| 220 | int sl_policy_get_root(void); /* drop SUID to root */
|
---|
| 221 |
|
---|
| 222 | /*
|
---|
| 223 | * If not using one of the above, use this function,
|
---|
| 224 | * and then call sh_unset_suid().
|
---|
| 225 | * This function saves the uid's.
|
---|
| 226 | * It calls abort() on error.
|
---|
| 227 | */
|
---|
| 228 | int sl_save_uids(void);
|
---|
| 229 |
|
---|
| 230 | /*
|
---|
| 231 | * This function returns the saved euid.
|
---|
| 232 | * It calls abort() if the uid's are not saved already.
|
---|
| 233 | */
|
---|
| 234 | int sl_get_euid(/*@out@*/uid_t * ret);
|
---|
| 235 | uid_t sl_ret_euid();
|
---|
| 236 |
|
---|
| 237 | /*
|
---|
| 238 | * This function returns the saved egid.
|
---|
| 239 | * It calls abort() if the uid's are not saved already.
|
---|
| 240 | */
|
---|
| 241 | int sl_get_egid(/*@out@*/gid_t * ret);
|
---|
| 242 |
|
---|
| 243 | /*
|
---|
| 244 | * This function returns the saved current ruid.
|
---|
| 245 | * It calls abort() if the uid's are not saved already.
|
---|
| 246 | */
|
---|
| 247 | int sl_get_ruid(/*@out@*/uid_t * ret);
|
---|
| 248 |
|
---|
| 249 | /*
|
---|
| 250 | * This function returns the saved current rgid.
|
---|
| 251 | * It calls abort() if the uid's are not saved already.
|
---|
| 252 | */
|
---|
| 253 | int sl_get_rgid(gid_t * ret);
|
---|
| 254 |
|
---|
| 255 | /*
|
---|
| 256 | * This function returns the saved original ruid.
|
---|
| 257 | * It calls abort() if the uid's are not saved already.
|
---|
| 258 | */
|
---|
| 259 | int sl_get_ruid_orig(uid_t * ret);
|
---|
| 260 |
|
---|
| 261 | /*
|
---|
| 262 | * This function returns the saved original rgid.
|
---|
| 263 | * It calls abort() if the uid's are not saved already.
|
---|
| 264 | */
|
---|
| 265 | int sl_get_rgid_orig(gid_t * ret);
|
---|
| 266 |
|
---|
| 267 | /*
|
---|
| 268 | * This function returns true if the program is SUID.
|
---|
| 269 | * It calls abort() if the uid's are not saved already.
|
---|
| 270 | */
|
---|
| 271 | int sl_is_suid(void);
|
---|
| 272 |
|
---|
| 273 | /*
|
---|
| 274 | * This function sets the effective uid
|
---|
| 275 | * to the saved effective uid.
|
---|
| 276 | */
|
---|
| 277 | int sl_set_suid (void);
|
---|
| 278 |
|
---|
| 279 | /*
|
---|
| 280 | * This function sets the effective uid to the real uid.
|
---|
| 281 | */
|
---|
| 282 | int sl_unset_suid (void);
|
---|
| 283 |
|
---|
| 284 | /*
|
---|
| 285 | * This function drops SUID privileges irrevocably.
|
---|
| 286 | */
|
---|
| 287 | int sl_drop_privileges(void);
|
---|
| 288 |
|
---|
| 289 | /* ----------------------------------------------------------------
|
---|
| 290 | *
|
---|
| 291 | * File handling routines
|
---|
| 292 | *
|
---|
| 293 | * ---------------------------------------------------------------- */
|
---|
| 294 |
|
---|
| 295 | SL_TICKET sl_make_ticket (int fd, char * path);
|
---|
| 296 |
|
---|
| 297 | /* Open for writing.
|
---|
| 298 | */
|
---|
| 299 | SL_TICKET sl_open_write (char * fname, int priviledge_mode);
|
---|
| 300 |
|
---|
| 301 | /* Open for reading.
|
---|
| 302 | */
|
---|
| 303 | SL_TICKET sl_open_read (char * fname, int priviledge_mode);
|
---|
| 304 |
|
---|
| 305 | /* Open for reading w/minimum checking.
|
---|
| 306 | */
|
---|
| 307 | SL_TICKET sl_open_fastread (char * fname, int priviledge_mode);
|
---|
| 308 |
|
---|
| 309 | /* Open for read and write.
|
---|
| 310 | */
|
---|
| 311 | SL_TICKET sl_open_rdwr (char * fname, int priviledge_mode);
|
---|
| 312 |
|
---|
| 313 | /* Open for read and write, fail if file exists.
|
---|
| 314 | */
|
---|
| 315 | SL_TICKET sl_open_safe_rdwr (char * fname, int priv);
|
---|
| 316 |
|
---|
| 317 | /* Open for write, truncate.
|
---|
| 318 | */
|
---|
| 319 | SL_TICKET sl_open_write_trunc (char * fname, int priviledge_mode);
|
---|
| 320 |
|
---|
| 321 | /* Open for read and write, truncate.
|
---|
| 322 | */
|
---|
| 323 | SL_TICKET sl_open_rdwr_trunc (char * fname, int priviledge_mode);
|
---|
| 324 |
|
---|
| 325 | /* Close file.
|
---|
| 326 | */
|
---|
| 327 | int sl_close (SL_TICKET ticket);
|
---|
| 328 |
|
---|
| 329 | /* Unlink file.
|
---|
| 330 | */
|
---|
| 331 | int sl_unlink (SL_TICKET ticket);
|
---|
| 332 |
|
---|
| 333 | /* Rewind file.
|
---|
| 334 | */
|
---|
| 335 | int sl_rewind (SL_TICKET ticket);
|
---|
| 336 |
|
---|
| 337 | /* Seek file.
|
---|
| 338 | */
|
---|
| 339 | int sl_seek (SL_TICKET ticket, off_t off_data);
|
---|
| 340 |
|
---|
| 341 | /* Forward file.
|
---|
| 342 | */
|
---|
| 343 | int sl_forward (SL_TICKET ticket);
|
---|
| 344 |
|
---|
| 345 | /* Sync file.
|
---|
| 346 | */
|
---|
| 347 | int sl_sync (SL_TICKET ticket);
|
---|
| 348 |
|
---|
| 349 | /* Read file.
|
---|
| 350 | */
|
---|
| 351 | int sl_read (SL_TICKET ticket, void * buf, size_t count);
|
---|
| 352 |
|
---|
[8] | 353 | int sl_read_timeout_prep (SL_TICKET ticket);
|
---|
| 354 |
|
---|
[1] | 355 | int sl_read_timeout (SL_TICKET ticket, void * buf,
|
---|
| 356 | size_t count, int timeout);
|
---|
| 357 |
|
---|
| 358 | int sl_read_fast (SL_TICKET ticket, void * buf_in, size_t count);
|
---|
| 359 |
|
---|
| 360 | /* Write file.
|
---|
| 361 | */
|
---|
| 362 | int sl_write (SL_TICKET ticket, void * msg, long nbytes);
|
---|
| 363 |
|
---|
| 364 | /* Write file, terminate with newline.
|
---|
| 365 | */
|
---|
| 366 | int sl_write_line (SL_TICKET ticket, void * msg, long nbytes);
|
---|
| 367 |
|
---|
| 368 | /* Drop all metadata for file descriptors >= fd.
|
---|
| 369 | */
|
---|
| 370 | int sl_dropall(int fd, int except);
|
---|
| 371 |
|
---|
| 372 | /* Check whether file is trustworthy.
|
---|
| 373 | */
|
---|
| 374 | int sl_trustfile(char * path, uid_t * ok, uid_t * bad);
|
---|
| 375 |
|
---|
| 376 | /* Check whether file is trustworthy.
|
---|
| 377 | */
|
---|
| 378 | int sl_trustfile_euid(char * filename, uid_t euid);
|
---|
| 379 |
|
---|
| 380 | /* purge list of trusted users
|
---|
| 381 | */
|
---|
| 382 | int sl_trust_purge_user ();
|
---|
| 383 |
|
---|
| 384 | /* Add a trusted user.
|
---|
| 385 | */
|
---|
| 386 | int sl_trust_add_user (uid_t pwid);
|
---|
| 387 |
|
---|
| 388 | /* Get error string.
|
---|
| 389 | */
|
---|
| 390 | char * sl_error_string(int errorcode);
|
---|
| 391 |
|
---|
| 392 | /* Get error file.
|
---|
| 393 | */
|
---|
| 394 | char * sl_trust_errfile(void);
|
---|
| 395 |
|
---|
| 396 |
|
---|
| 397 | #ifdef __cplusplus
|
---|
| 398 | }
|
---|
| 399 | #endif
|
---|
| 400 |
|
---|
| 401 | /* Privilege modes for file access.
|
---|
| 402 | */
|
---|
| 403 | #define SL_YESPRIV 0x33
|
---|
| 404 | #define SL_NOPRIV 0x34
|
---|
| 405 |
|
---|
| 406 | #define MAXFILENAME 2048
|
---|
| 407 |
|
---|
| 408 |
|
---|
| 409 | /*
|
---|
| 410 | * This macro is TRUE if (x) < 0.
|
---|
| 411 | */
|
---|
| 412 | #define SL_ISERROR(x) ((long)(x) < 0)
|
---|
| 413 |
|
---|
| 414 | #if defined(WITH_TPT)
|
---|
| 415 | #define TPT(arg) dlog arg ;
|
---|
| 416 | #else
|
---|
| 417 | #define TPT(arg)
|
---|
| 418 | #endif
|
---|
| 419 |
|
---|
| 420 |
|
---|
| 421 | /*
|
---|
| 422 | * The 'require' macro.
|
---|
| 423 | */
|
---|
| 424 | #define SL_REQUIRE(assertion, astext) \
|
---|
| 425 | do { \
|
---|
| 426 | /*@i@*/ if (assertion) ; \
|
---|
| 427 | else { \
|
---|
| 428 | dlog(0, FIL__, __LINE__, SDG_AFAIL, \
|
---|
| 429 | FIL__, __LINE__, astext); \
|
---|
| 430 | _exit(EXIT_FAILURE); \
|
---|
| 431 | } \
|
---|
| 432 | } while (0)
|
---|
| 433 |
|
---|
| 434 |
|
---|
| 435 | /*
|
---|
| 436 | * The enter macro. Prints the trace if TRACE is on.
|
---|
| 437 | */
|
---|
| 438 | extern int slib_do_trace;
|
---|
| 439 | extern int slib_trace_fd;
|
---|
| 440 |
|
---|
| 441 | #if defined(SL_DEBUG)
|
---|
| 442 | #define SL_ENTER(s) sl_stack_push(s, FIL__, __LINE__);
|
---|
| 443 | #else
|
---|
| 444 | #define SL_ENTER(s) if (slib_do_trace != 0) sl_trace_in(s, FIL__, __LINE__);
|
---|
| 445 | #endif
|
---|
| 446 |
|
---|
| 447 | /*
|
---|
| 448 | * The return macro.
|
---|
| 449 | */
|
---|
| 450 | #if defined(SL_DEBUG)
|
---|
| 451 | #ifndef S_SPLINT_S
|
---|
| 452 | #define SL_RETURN(x, s) \
|
---|
| 453 | do { \
|
---|
| 454 | sl_stack_pop(s, FIL__, __LINE__); \
|
---|
| 455 | return(x); \
|
---|
| 456 | } while(0)
|
---|
| 457 | #else
|
---|
| 458 | /*@notfunction@*/
|
---|
| 459 | #define SL_RETURN(x, s) return(x);
|
---|
| 460 | #endif /* S_SPLINT_S */
|
---|
| 461 | #else
|
---|
| 462 | #ifndef S_SPLINT_S
|
---|
| 463 | #define SL_RETURN(x, s) \
|
---|
| 464 | do { \
|
---|
| 465 | if (slib_do_trace != 0) \
|
---|
| 466 | sl_trace_out(s, FIL__, __LINE__); \
|
---|
| 467 | return(x); \
|
---|
| 468 | } while(0)
|
---|
| 469 | #else
|
---|
| 470 | /*@notfunction@*/
|
---|
| 471 | #define SL_RETURN(x, s) return(x);
|
---|
| 472 | #endif /* S_SPLINT_S */
|
---|
| 473 | #endif /* SL_RETURN macro */
|
---|
| 474 |
|
---|
| 475 | #if defined(SL_DEBUG)
|
---|
| 476 | #define SL_RET0(s) \
|
---|
| 477 | do { \
|
---|
| 478 | sl_stack_pop(s, FIL__, __LINE__); \
|
---|
| 479 | return; \
|
---|
| 480 | } while(0)
|
---|
| 481 | #else
|
---|
| 482 | #ifndef S_SPLINT_S
|
---|
| 483 | #define SL_RET0(s) \
|
---|
| 484 | do { \
|
---|
| 485 | if (slib_do_trace != 0) \
|
---|
| 486 | sl_trace_out(s, FIL__, __LINE__); \
|
---|
| 487 | return; \
|
---|
| 488 | } while(0)
|
---|
| 489 | #else
|
---|
| 490 | /*@notfunction@*/
|
---|
| 491 | #define SL_RET0(s) return;
|
---|
| 492 | #endif /* S_SPLINT_S */
|
---|
| 493 | #endif /* SL_RETURN macro */
|
---|
| 494 |
|
---|
| 495 | #if defined(SL_DEBUG)
|
---|
| 496 | void sl_stack_push(char * c, char * file, int line);
|
---|
| 497 | void sl_stack_pop(char * c, char * file, int line);
|
---|
| 498 | void sl_stack_print();
|
---|
| 499 | #endif
|
---|
| 500 | void sl_trace_in (char * str, char * file, int line);
|
---|
| 501 | void sl_trace_out (char * str, char * file, int line);
|
---|
| 502 | int sl_trace_file (char * str);
|
---|
| 503 | int sl_trace_use (char * str);
|
---|
| 504 |
|
---|
| 505 |
|
---|
| 506 |
|
---|
| 507 |
|
---|
| 508 | /*
|
---|
| 509 | * The internal return macro. Sets sl_errno to the return value.
|
---|
| 510 | */
|
---|
| 511 |
|
---|
| 512 | #if defined(SL_DEBUG)
|
---|
| 513 | #define SL_IRETURN(x, s) \
|
---|
| 514 | do { \
|
---|
| 515 | if((long)(x) < 0) { \
|
---|
| 516 | TPT((0, FIL__, __LINE__, SDG_ERROR, (long)(x))) \
|
---|
| 517 | sl_errno=(x); \
|
---|
| 518 | } \
|
---|
| 519 | sl_stack_pop(s, FIL__, __LINE__); \
|
---|
| 520 | if (1) return(x); \
|
---|
| 521 | } while(0)
|
---|
| 522 | #else
|
---|
| 523 | #define SL_IRETURN(x, s) \
|
---|
| 524 | do { \
|
---|
| 525 | if ((long)(x) < 0) sl_errno=(x); \
|
---|
| 526 | if (slib_do_trace) \
|
---|
| 527 | sl_trace_out(s, FIL__, __LINE__); \
|
---|
| 528 | if (1) return(x); \
|
---|
| 529 | } while(0)
|
---|
| 530 |
|
---|
| 531 | #endif /* SL_IRETURN macro */
|
---|
| 532 |
|
---|
| 533 |
|
---|
| 534 |
|
---|
| 535 | /* slib.h */
|
---|
| 536 | #endif
|
---|
| 537 |
|
---|
| 538 |
|
---|
| 539 |
|
---|
| 540 |
|
---|