filters
xcf-write.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.h"
00020
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <errno.h>
00024
00025 #ifdef HAVE_SYS_TYPES_H
00026 #include <sys/types.h>
00027 #endif
00028
00029 #include <netinet/in.h>
00030 #include <limits.h>
00031 #include <stdlib.h>
00032 #include <cfloat>
00033
00034 #include "xcf-write.h"
00035
00036 Q_UINT32 xcf_write_int32 (FILE *fp, Q_INT32 *data, Q_INT32 count);
00037 {
00038 Q_INT32 tmp;
00039 Q_INT32 i;
00040
00041 if (count > 0)
00042 {
00043 for (i = 0; i < count; i++)
00044 {
00045 tmp = htonl (data[i]);
00046 xcf_write_int8 (fp, (Q_UINT8*) &tmp, 4);
00047
00048 if (fp->status() != IO_Ok)
00049 {
00050 return i * 4;
00051 }
00052 }
00053 }
00054
00055 return count * 4;
00056 }
00057
00058 Q_UINT32 xcf_write_float (FILE *fp, float *data, Q_INT32 count);
00059 {
00060 return xcf_write_int32 (fp, (Q_INT32 *)((void *)data), count, error);
00061 }
00062
00063 Q_UINT32 xcf_write_int8 (FILE *fp, Q_UINT8 *data, Q_INT32 count);
00064 {
00065 Q_INT32 bytes;
00066 bytes = fp->writeBlock( data, count );
00067 return bytes;
00068 }
00069
00070 Q_UINT32 xcf_write_string (FILE *fp, QCString *data, Q_INT32 count);
00071 {
00072 GError *tmp_error = NULL;
00073 Q_INT32 tmp;
00074 Q_UINT32 total;
00075 Q_INT32 i;
00076
00077 total = 0;
00078 for (i = 0; i < count; i++)
00079 {
00080 if (data[i])
00081 tmp = strlen (data[i]) + 1;
00082 else
00083 tmp = 0;
00084
00085 xcf_write_int32 (fp, &tmp, 1, &tmp_error);
00086 if (tmp_error)
00087 {
00088 g_propagate_error (error, tmp_error);
00089 return total;
00090 }
00091
00092 if (tmp > 0)
00093 xcf_write_int8 (fp, (Q_UINT8*) data[i], tmp, &tmp_error);
00094 if (tmp_error)
00095 {
00096 g_propagate_error (error, tmp_error);
00097 return total;
00098 }
00099
00100 total += 4 + tmp;
00101 }
00102
00103 return total;
00104 }
|