Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
344 volume VI os16<br />
Sorgenti della libreria generale 345<br />
«<br />
105.9.43 lib/stdio/vsscanf.c<br />
Si veda la sezione 98.129.<br />
2880019 | //<br />
2880020 | while (1);<br />
2880021 |}<br />
2860001 |#include <br />
2860002 |<br />
«<br />
«<br />
2860003 |//----------------------------------------------------------------------<br />
2860004 |int vfsscanf (FILE *restrict fp, const char *string,<br />
2860005 | const char *restrict format, va_list ap);<br />
2860006 |//----------------------------------------------------------------------<br />
2860007 |int<br />
2860008 |vsscanf (const char *string, const char *restrict format, va_list ap)<br />
2860009 |{<br />
2860010 | return (vfsscanf (NULL, string, format, ap));<br />
2860011 |}<br />
2860012 |//----------------------------------------------------------------------<br />
105.10 os16: «lib/stdlib.h»<br />
Si veda la sezione 101.2.<br />
2870001 |#ifndef _STDLIB_H<br />
2870002 |#define _STDLIB_H 1<br />
2870003 |//----------------------------------------------------------------------<br />
2870004 |<br />
2870005 |#include <br />
2870006 |#include <br />
2870007 |#include <br />
2870008 |#include <br />
2870009 |#include <br />
2870010 |#include <br />
2870011 |//----------------------------------------------------------------------<br />
2870012 |typedef struct {<br />
2870013 | int quot;<br />
2870014 | int rem;<br />
2870015 |} div_t;<br />
2870016 |//----------------------------------------------------------------------<br />
2870017 |typedef struct {<br />
2870018 | long int quot;<br />
2870019 | long int rem;<br />
2870020 |} ldiv_t;<br />
2870021 |//----------------------------------------------------------------------<br />
2870022 |typedef void (*atexit_t) (void); // Non standard. [1]<br />
2870023 |//<br />
2870024 |// [1] The type ‘atexit_t’ is a pointer to a function for the "at exit"<br />
2870025 |// procedure, with no parameters and returning void. With the<br />
2870026 |// declaration of type ‘atexit_t’, the function prototype of<br />
2870027 |// ‘atexit()’ is easier to declare and to understand. Original<br />
2870028 |// declaration is:<br />
2870029 |//<br />
2870030 |// int atexit (void (*function) (void));<br />
2870031 |//<br />
2870032 |//----------------------------------------------------------------------<br />
2870033 |#define EXIT_FAILURE 1<br />
2870034 |#define EXIT_SUCCESS 0<br />
2870035 |#define RAND_MAX INT_MAX<br />
2870036 |#define MB_CUR_MAX ((size_t) MB_LEN_MAX)<br />
2870037 |//----------------------------------------------------------------------<br />
2870038 |void _Exit (int status);<br />
2870039 |void abort (void);<br />
2870040 |int abs (int j);<br />
2870041 |int atexit (atexit_t function);<br />
2870042 |int atoi (const char *string);<br />
2870043 |long int atol (const char *string);<br />
2870044 |//void *bsearch (const void *key, const void *base,<br />
2870045 |// size_t nmemb, size_t size,<br />
2870046 |// int (*compar) (const void *, const void *));<br />
2870047 |#define calloc(b, s) (malloc ((b) * (s)))<br />
2870048 |div_t div (int numer, int denom);<br />
2870049 |void exit (int status);<br />
2870050 |void free (void *ptr);<br />
2870051 |char *getenv (const char *name);<br />
2870052 |long int labs (long int j);<br />
2870053 |ldiv_t ldiv (long int numer, long int denom);<br />
2870054 |void *malloc (size_t size);<br />
2870055 |int putenv (const char *string);<br />
2870056 |void qsort (void *base, size_t nmemb, size_t size,<br />
2870057 | int (*compare) (const void *,<br />
2870058 | const void *));<br />
2870059 |int rand (void);<br />
2870060 |void *realloc (void *ptr, size_t size);<br />
2870061 |int setenv (const char *name, const char *value,<br />
2870062 | int overwrite);<br />
2870063 |void srand (unsigned int seed);<br />
2870064 |long int strtol (const char *restrict string,<br />
2870065 | char **restrict endptr, int base);<br />
2870066 |unsigned long int strtoul (const char * restrict string,<br />
2870067 | char ** restrict endptr, int base);<br />
2870068 |//int system (const char *string);<br />
2870069 |int unsetenv (const char *name);<br />
2870070 |<br />
2870071 |#endif<br />
105.10.1 lib/stdlib/_Exit.c<br />
Si veda la sezione 97.2.<br />
2880001 |#include <br />
2880002 |#include <br />
2880003 |//----------------------------------------------------------------------<br />
2880004 |void<br />
2880005 |_Exit (int status)<br />
2880006 |{<br />
2880007 | sysmsg_exit_t msg;<br />
2880008 | //<br />
2880009 | // Only the low eight bit are returned.<br />
2880010 | //<br />
2880011 | msg.status = (status & 0xFF);<br />
2880012 | //<br />
2880013 | //<br />
2880014 | //<br />
2880015 | sys (SYS_EXIT, &msg, (sizeof msg));<br />
2880016 | //<br />
2880017 | // Should not return from system call, but if it does, loop<br />
2880018 | // forever:<br />
105.10.2 lib/stdlib/abort.c<br />
Si veda la sezione 98.2.<br />
2890001 |#include <br />
2890002 |#include <br />
2890003 |#include <br />
2890004 |#include <br />
2890005 |//----------------------------------------------------------------------<br />
2890006 |void<br />
2890007 |abort (void)<br />
2890008 |{<br />
2890009 | pid_t pid;<br />
2890010 | sighandler_t sig_previous;<br />
2890011 | //<br />
2890012 | // Set ‘SIGABRT’ to a default action.<br />
2890013 | //<br />
2890014 | sig_previous = signal (SIGABRT, SIG_DFL);<br />
2890015 | //<br />
2890016 | // If the previous action was something different than symbolic<br />
2890017 | // ones, configure again the previous action.<br />
2890018 | //<br />
2890019 | if (sig_previous != SIG_DFL &&<br />
2890020 | sig_previous != SIG_IGN &&<br />
2890021 | sig_previous != SIG_ERR)<br />
2890022 | {<br />
2890023 | signal (SIGABRT, sig_previous);<br />
2890024 | }<br />
2890025 | //<br />
2890026 | // Get current process ID and sent the signal.<br />
2890027 | //<br />
2890028 | pid = getpid ();<br />
2890029 | kill (pid, SIGABRT);<br />
2890030 | //<br />
2890031 | // Second chance<br />
2890032 | //<br />
2890033 | for (;;)<br />
2890034 | {<br />
2890035 | signal (SIGABRT, SIG_DFL);<br />
2890036 | pid = getpid ();<br />
2890037 | kill (pid, SIGABRT);<br />
2890038 | }<br />
2890039 |}<br />
105.10.3 lib/stdlib/abs.c<br />
Si veda la sezione 98.3.<br />
2900001 |#include <br />
2900002 |//----------------------------------------------------------------------<br />
2900003 |int<br />
2900004 |abs (int j)<br />
2900005 |{<br />
2900006 | if (j < 0)<br />
2900007 | {<br />
2900008 | return -j;<br />
2900009 | }<br />
2900010 | else<br />
2900011 | {<br />
2900012 | return j;<br />
2900013 | }<br />
2900014 |}<br />
105.10.4 lib/stdlib/alloc.c<br />
Si veda la sezione 98.66.<br />
2910001 |#include <br />
2910002 |#include <br />
2910003 |#include <br />
2910004 |#include <br />
2910005 |#include <br />
2910006 |//----------------------------------------------------------------------<br />
2910007 |#define MEMORY_BLOCK_SIZE 1024<br />
2910008 |//----------------------------------------------------------------------<br />
2910009 |static char _alloc_memory[LONG_BIT][MEMORY_BLOCK_SIZE]; // [1]<br />
2910010 |static size_t _alloc_size[LONG_BIT]; // [2]<br />
2910011 |static long int _alloc_map; // [3]<br />
2910012 |//<br />
2910013 |// [1] Memory to be allocated.<br />
2910014 |// [2] Sizes allocated.<br />
2910015 |// [3] Memory block map. The memory map is made of a single integer and<br />
2910016 |// the rightmost bit is the first memory block.<br />
2910017 |//----------------------------------------------------------------------<br />
2910018 |void *<br />
2910019 |malloc (size_t size)<br />
2910020 |{<br />
2910021 | size_t size_free; // Size free found that might be allocated.<br />
2910022 | int m; // Index inside ‘_alloc_memory[][]’ table.<br />
2910023 | int s; // Start index for a free memory area.<br />
2910024 | long int mask; // Mask to compare with ‘_alloc_map’.<br />
2910025 | long int alloc; // New allocation map.<br />
2910026 | //<br />
2910027 | // Check for arguments.<br />
2910028 | //<br />
2910029 | if (size == 0)<br />
2910030 | {<br />
2910031 | return (NULL);<br />
2910032 | }<br />
2910033 | //<br />
2910034 | for (s = 0, m = 0; m < LONG_BIT; m++)<br />
2910035 | {<br />
2910036 | mask = 1;<br />
2910037 | mask