Annotation of coherent/g/usr/bin/pax/mem.c, revision 1.1.1.1

1.1       root        1: /* $Source: /src386/usr/bin/pax/mem.c,v $
                      2:  *
                      3:  * $Revision: 1.1 $
                      4:  *
                      5:  * mem.c - memory allocation and manipulation functions
                      6:  *
                      7:  * DESCRIPTION
                      8:  *
                      9:  *     These routines are provided for higher level handling of the UNIX
                     10:  *     memory allocation functions.
                     11:  *
                     12:  * AUTHOR
                     13:  *
                     14:  *     Mark H. Colburn, NAPS International ([email protected])
                     15:  *
                     16:  *
                     17:  * Sponsored by The USENIX Association for public distribution. 
                     18:  *
                     19:  * Copyright (c) 1989 Mark H. Colburn.
                     20:  * All rights reserved.
                     21:  *
                     22:  * Redistribution and use in source and binary forms are permitted
                     23:  * provided that the above copyright notice is duplicated in all such 
                     24:  * forms and that any documentation, advertising materials, and other 
                     25:  * materials related to such distribution and use acknowledge that the 
                     26:  * software was developed * by Mark H. Colburn and sponsored by The 
                     27:  * USENIX Association. 
                     28:  *
                     29:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     30:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     31:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     32:  *
                     33:  * $Log:       mem.c,v $
                     34:  * Revision 1.1  92/08/28  08:02:18  bin
                     35:  * Initial revision
                     36:  * 
                     37:  * Revision 1.1  89/02/14  16:48:01  jep
                     38:  * Initial revision
                     39:  * 
                     40:  * Revision 1.1  88/12/23  18:02:17  mark
                     41:  * Initial revision
                     42:  * 
                     43:  */
                     44: 
                     45: #ifndef lint
                     46: static char *ident = "$Id: mem.c,v 1.1 92/08/28 08:02:18 bin Exp Locker: bin $";
                     47: static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
                     48: #endif /* ! lint */
                     49: 
                     50: 
                     51: /* Headers */
                     52: 
                     53: #include "pax.h"
                     54: 
                     55: 
                     56: /* mem_get - allocate memory
                     57:  *
                     58:  * DESCRIPTION
                     59:  *
                     60:  *     Mem_get attempts to allocate a block of memory using the malloc
                     61:  *     function call.  In the event that the memory is not available, 
                     62:  *     mem_get will display an "Out of memory" message for the user
                     63:  *     the first time it encounters the an out of memory situation.
                     64:  *     Subsequent calls to mem_get may fail, but no message will be
                     65:  *     printed.
                     66:  *
                     67:  * PARAMETERS
                     68:  *
                     69:  *     uint len        - The amount of memory to allocate
                     70:  *
                     71:  * RETURNS
                     72:  *
                     73:  *     Normally returns the pointer to the newly allocated memory.  If
                     74:  *     an error occurs, NULL is returned, and an error message is
                     75:  *     printed.
                     76:  *
                     77:  * ERRORS
                     78:  *
                     79:  *     ENOMEM  No memory is available 
                     80:  */
                     81: 
                     82: #if __STDC__
                     83: 
                     84: char *mem_get(uint len)
                     85: 
                     86: #else
                     87: 
                     88: char *mem_get(len)
                     89: uint            len;           /* amount of memory to get */
                     90: 
                     91: #endif
                     92: {
                     93:     char           *mem;
                     94:     static short    outofmem = 0;
                     95: 
                     96:     if ((mem = (char *)malloc(len)) == (char *)NULL && !outofmem) {
                     97:        outofmem++;
                     98:        warn("mem_get()", "Out of memory");
                     99:     }
                    100:     return (mem);
                    101: }
                    102: 
                    103: 
                    104: /* mem_str - duplicate a string into dynamic memory
                    105:  *
                    106:  * DESCRIPTION
                    107:  *
                    108:  *     Mem_str attempts to make a copy of string.  It allocates space for
                    109:  *     the string, and if the allocation was successfull, copies the old
                    110:  *     string into the newly allocated space.
                    111:  *
                    112:  * PARAMETERS
                    113:  *
                    114:  *     char *str       - string to make a copy of 
                    115:  *
                    116:  * RETURNS
                    117:  *
                    118:  *     Normally returns a pointer to a new string at least as large
                    119:  *     as strlen(str) + 1, which contains a copy of the the data 
                    120:  *     passed in str, plus a null terminator.  Returns (char *)NULL 
                    121:  *     if enough memory to make a copy of str is not available.
                    122:  */
                    123: 
                    124: #if __STDC__
                    125: 
                    126: char *mem_str(char *str)
                    127: 
                    128: #else
                    129: 
                    130: char *mem_str(str)
                    131: char           *str;           /* string to make a copy of */
                    132: 
                    133: #endif
                    134: {
                    135:     char           *mem;
                    136: 
                    137:     if (mem = mem_get((uint) strlen(str) + 1)) {
                    138:        strcpy(mem, str);
                    139:     }
                    140:     return (mem);
                    141: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.