- Main Page
- Related Pages
- Data Structures
- Files
- Examples

- File List

# /home/v/Kate/WORK_TREES/kate-sorceress-backup/v/src/kate/src/kate_packet.c

    00001 /* Copyright (C) 2008 Vincent Penquerc'h.
    00002    This file is part of the Kate codec library.
    00003    Written by Vincent Penquerc'h.
    00004
    00005    Use, distribution and reproduction of this library is governed
    00006    by a BSD style source license included with this source in the
    00007    file 'COPYING'. Please read these terms before distributing. */
    00008
    00009
    00010 #define KATE_INTERNAL
    00011 #include "kate_internal.h"
    00012
    00013 #ifdef HAVE_STDLIB_H
    00014 #include <stdlib.h>
    00015 #endif
    00016 #include <string.h>
    00017 #include "kate/kate.h"
    00018
    00030 int kate_packet_wrap(kate_packet *kp,size_t nbytes,const void *data)
    00031 {
    00032   if (!kp) return KATE_E_INVALID_PARAMETER;
    00033   if (!data && nbytes>0) return KATE_E_INVALID_PARAMETER;
    00034
    00035   kp->nbytes=nbytes;
    00036   kp->data=(void*)data;
    00037   /* kp->data is not const as it may be freed; however, here, data will
    00038      always be const as it may be a const buffer given by the user, in
    00039      which case it won't be freed */
    00040
    00041   return 0;
    00042 }
    00043
    00055 int kate_packet_init(kate_packet *kp,size_t nbytes,const void *data)
    00056 {
    00057   void *dup_data;
    00058
    00059   if (!kp) return KATE_E_INVALID_PARAMETER;
    00060   if (!data && nbytes>0) return KATE_E_INVALID_PARAMETER;
    00061
    00062   dup_data=kate_malloc(nbytes);
    00063   if (!dup_data) return KATE_E_OUT_OF_MEMORY;
    00064   if (data) memcpy(dup_data,data,nbytes);
    00065
    00066   return kate_packet_wrap(kp,nbytes,dup_data);
    00067 }
    00068
    00076 int kate_packet_clear(kate_packet *kp)
    00077 {
    00078   if (!kp) return KATE_E_INVALID_PARAMETER;
    00079
    00080   if (kp->data) {
    00081     kate_free(kp->data);
    00082     kp->data=NULL;
    00083   }
    00084
    00085   return 0;
    00086 }
    00087