home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / a / bin / modules-.2 / modules- / modules-1.2.8 / depmod / alloctxt.c next >
Encoding:
C/C++ Source or Header  |  1995-05-30  |  998 b   |  48 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "link.h"
  4.  
  5. #define ALLOC_TXT    20000    // Dimension du buffer pour allocation
  6.                             // des chaines.
  7.  
  8.  
  9. static char *ptacc = NULL;
  10. static char *lastacc = NULL;
  11.  
  12. char *strdup_err (const char *str, int quit)
  13. {
  14.     char *ret = strdup(str);
  15.     if (ret == NULL){
  16.         depmod_error ("Can't allocate %d bytes of memory",strlen(str)+1);
  17.         if (quit) exit (-1);
  18.     }
  19.     return ret;
  20. }
  21. void *malloc_err (int size, int quit)
  22. {
  23.     void *ret = malloc(size);
  24.     if (ret == NULL){
  25.         depmod_error ("Can't allocate %d bytes of memory",size);
  26.         if (quit) exit (-1);
  27.     }
  28.     return ret;
  29. }
  30. /*
  31.     Accumule une chaine dans un tableau dynamique et retourne son adresse.
  32.     C'est l'équivalent d'un strdup rapide sans liberation possible.
  33. */
  34. char *alloctxt_add (const char *str)
  35. {
  36.     int len = strlen(str) + 1;
  37.     if (ptacc == NULL || ptacc + len >= lastacc){
  38.         ptacc = (char*)malloc_err (ALLOC_TXT,1);
  39.         lastacc = ptacc + ALLOC_TXT;
  40.     }
  41.     strcpy (ptacc,str);
  42.     char *ret = ptacc;
  43.     ptacc += len;
  44.     return ret;
  45. }
  46.  
  47.  
  48.