Back to index

im-sdk  12.3.91
comp-binaryfile-object.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <sys/types.h>
00005 
00006 #include <iiimp-data.h>
00007 
00008 #include "iiimp-dataP.h"
00009 
00010 
00011 IIIMP_binaryfile_object *
00012 iiimp_binaryfile_object_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_string *   object)
00015 {
00016     IIIMP_binaryfile_object *      bin_obj;
00017 
00018     bin_obj = (IIIMP_binaryfile_object *)
00019        malloc(sizeof (IIIMP_binaryfile_object));
00020     if (NULL == bin_obj) {
00021        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00022        return NULL;
00023     }
00024 
00025     bin_obj->object = object;
00026     if (NULL == object) {
00027        bin_obj->nbyte = 4;
00028     } else {
00029        bin_obj->nbyte = object->nbyte;
00030     }
00031 
00032        return bin_obj;
00033 }
00034 
00035 
00036 void
00037 iiimp_binaryfile_object_delete(
00038     IIIMP_data_s *          data_s,
00039     IIIMP_binaryfile_object *      bin_obj)
00040 {
00041     if (NULL == bin_obj) return;
00042     iiimp_string_delete(data_s, bin_obj->object);
00043     free(bin_obj);
00044     return;
00045 }
00046 
00047 
00048 void
00049 iiimp_binaryfile_object_pack(
00050     IIIMP_data_s *          data_s,
00051     IIIMP_binaryfile_object *      m,
00052     size_t *                nbyte,
00053     uchar_t **                     ptr)
00054 {
00055     size_t                  rest;
00056     uchar_t *               p;
00057 
00058     rest = *nbyte;
00059     p = *ptr;
00060 
00061     iiimp_string_pack(data_s, m->object, &rest, &p);
00062 
00063     *nbyte = rest;
00064     *ptr = p;
00065 
00066     return;
00067 }
00068 
00069 
00070 IIIMP_binaryfile_object *
00071 iiimp_binaryfile_object_unpack(
00072     IIIMP_data_s *   data_s,
00073     size_t *         nbyte,
00074     const uchar_t ** ptr,
00075     size_t           nbyte_max)
00076 {
00077     IIIMP_binaryfile_object *      bin_obj;
00078     size_t                  rest;
00079     const uchar_t *         p;
00080 
00081     rest = nbyte_max;
00082     p = *ptr;
00083 
00084     if ((*nbyte < rest) || (rest < 4)) {
00085        data_s->status = IIIMP_DATA_INVALID;
00086        return NULL;
00087     }
00088 
00089     bin_obj = (IIIMP_binaryfile_object *)
00090        malloc(sizeof (IIIMP_binaryfile_object));
00091     if (NULL == bin_obj) {
00092        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00093        return NULL;
00094     }
00095 
00096     bin_obj->object = iiimp_string_unpack(data_s, &rest, &p, rest);
00097     if (NULL == bin_obj->object) {
00098        free(bin_obj);
00099        return NULL;
00100     }
00101 
00102     *nbyte = rest;
00103     *ptr = p;
00104 
00105     return bin_obj;
00106 }
00107 
00108 
00109 void
00110 iiimp_binaryfile_object_print(
00111     IIIMP_data_s *          data_s,
00112     IIIMP_binaryfile_object *      m)
00113 {
00114     if (NULL == m) return;
00115 
00116     iiimp_string_print(data_s, m->object);
00117 }
00118 
00119 
00120 /* Local Variables: */
00121 /* c-file-style: "iiim-project" */
00122 /* End: */