home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / IO / EADWRITE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  2.0 KB  |  85 lines

  1. /* eadwrite.c (emx+gcc) -- Copyright (c) 1993 by Eberhard Mattes */
  2.  
  3. #define INCL_DOSFILEMGR
  4. #include <os2.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <io.h>
  8. #include <errno.h>
  9. #include <sys/ead.h>
  10. #include "ea.h"
  11.  
  12. struct del_data
  13. {
  14.   int fea_alloc;
  15.   int fea_used;
  16.   ULONG *patch;
  17.   PFEA2LIST fea_ptr;
  18. };
  19.  
  20.  
  21. static int _ead_del (struct _ead_data *ead, PDENA2 pdena, void *arg)
  22. {
  23.   int add;
  24.   PFEA2 pfea;
  25.   struct del_data *p;
  26.  
  27.   if (_ead_find (ead, pdena->szName) < 0)
  28.     {
  29.       p = arg;
  30.       add = _EA_SIZE1 (pdena->cbName, 0);
  31.       if (p->fea_used + add > p->fea_alloc)
  32.         {
  33.           p->fea_alloc += 512;          /* increment must be > add */
  34.           p->fea_ptr = realloc (p->fea_ptr, p->fea_alloc);
  35.           if (p->fea_ptr == NULL)
  36.             return (-1);
  37.         }
  38.       pfea = (PFEA2)((char *)p->fea_ptr + p->fea_used);
  39.       pfea->oNextEntryOffset = add;
  40.       pfea->fEA = 0;
  41.       pfea->cbName = pdena->cbName;
  42.       pfea->cbValue = 0;        /* Delete! */
  43.       memcpy (pfea->szName, pdena->szName, pdena->cbName + 1);
  44.       p->patch = &pfea->oNextEntryOffset;
  45.       p->fea_used += add;
  46.     }
  47.   return (0);
  48. }
  49.  
  50.  
  51. int _ead_write (_ead ead, const char *path, int handle, int flags)
  52. {
  53.   if (_osmode != OS2_MODE)
  54.     return (0);
  55.   if (!(flags & _EAD_MERGE))
  56.     {
  57.       struct del_data dd;
  58.  
  59.       dd.fea_used = sizeof (ULONG);
  60.       dd.fea_alloc = 0;
  61.       dd.fea_ptr = NULL;
  62.       dd.patch = NULL;
  63.       if (_ead_enum (ead, path, handle, _ead_del, &dd) < 0)
  64.         {
  65.           if (dd.fea_ptr != NULL)
  66.             free (dd.fea_ptr);
  67.           return (-1);
  68.         }
  69.       if (dd.fea_ptr != NULL)
  70.         {
  71.           *dd.patch = 0;
  72.           dd.fea_ptr->cbList = dd.fea_used;
  73.           if (_ea_write (path, handle, dd.fea_ptr) < 0)
  74.             {
  75.               free (dd.fea_ptr);
  76.               return (-1);
  77.             }
  78.           free (dd.fea_ptr);
  79.         }
  80.     }
  81.   if (ead->count != 0 && _ea_write (path, handle, ead->buffer) < 0)
  82.     return (-1);
  83.   return (0);
  84. }
  85.