home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 530b.lha / AMenu_v1.3 / AllocStr.h < prev    next >
C/C++ Source or Header  |  1991-07-03  |  2KB  |  39 lines

  1. /*********************************************************************\
  2. **                               ________________________________    **
  3. **    A n t h o n y             |________    __    __    ________|   **
  4. **                                       |  |o_|  |o_|  |            **
  5. **            T h y s s e n            __|   __    __   |__          **
  6. **                                  __|   __|  |  |  |__   |__       **
  7. **   `` Dragon Computing ! ''    __|   __|     |  |     |__   |__    **
  8. **                              |_____|        |__|        |_____|   **
  9. **                                                                   **
  10. \*********************************************************************/
  11. /*   A collection of macro routines to handler the allocation
  12. ** and deallocation of strings better
  13. */
  14. #include <Proto/Exec.h>    /* for AllocMem() */
  15. #include <Exec/Memory.h>   /* for memory type flags */
  16. #include <string.h>        /* use builtin strcpy */
  17.  
  18. #ifdef AMIGA
  19.  
  20.     /* allocate and copy string -- EG: NewStr=AllocStr(OldStr) */
  21. # define AllocStr(str) \
  22.     strcpy((char *)AllocMem(strlen((str))+1,MEMF_PUBLIC), (str))
  23.  
  24.     /* Free the prevously allocated string and assign NULL */
  25. # define FreeStr(str) \
  26.     (FreeMem((str), strlen((str))+1), (str)=NULL)
  27.  
  28. #else /* assume standard C interface */
  29.  
  30.     /* allocate and copy string -- EG: NewStr=AllocStr(OldStr) */
  31. # define AllocStr(str) \
  32.     strcpy((char *)malloc(strlen((str))+1,MEMF_PUBLIC), (str))
  33.  
  34.     /* Free the prevously allocated string and assign NULL */
  35. # define FreeStr(str) \
  36.     (free((str)), (str)=NULL)
  37.  
  38. #endif
  39.