fixed 4 uses of un-inirialized vars + some compiler warnings.
[blender.git] / source / blender / imbuf / intern / cineon / logmemfile.c
1 /** \file blender/imbuf/intern/cineon/logmemfile.c
2  *  \ingroup imbcineon
3  */
4 /*
5  *       Cineon image file format library routines.
6  *
7  *       Copyright 2006 Joseph Eagar (joeedh@gmail.com)
8  *
9  *       This program is free software; you can redistribute it and/or modify it
10  *       under the terms of the GNU General Public License as published by the Free
11  *       Software Foundation; either version 2 of the License, or (at your option)
12  *       any later version.
13  *
14  *       This program is distributed in the hope that it will be useful, but
15  *       WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  *       or FITNESS FOR A PARTICULAR PURPOSE.    See the GNU General Public License
17  *       for more details.
18  *
19  *       You should have received a copy of the GNU General Public License
20  *       along with this program; if not, write to the Free Software
21  *       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  */
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "logImageCore.h"
29
30 int logimage_fseek(void* logfile, intptr_t offsett, int origin)
31 {       
32         struct _Log_Image_File_t_ *file = (struct _Log_Image_File_t_*) logfile;
33         intptr_t offset = offsett;
34         
35         if (file->file) fseek(file->file, offset, origin);
36         else { /*we're seeking in memory*/
37                 if (origin==SEEK_SET) {
38                         if (offset > file->membuffersize) return 1;
39                         file->memcursor = file->membuffer + offset;
40                 } else if (origin==SEEK_END) {
41                         if (offset > file->membuffersize) return 1;
42                         file->memcursor = (file->membuffer + file->membuffersize) - offset;
43                 } else if (origin==SEEK_CUR) {
44                         uintptr_t pos = (uintptr_t)file->membuffer - (uintptr_t)file->memcursor;
45                         if (pos + offset > file->membuffersize) return 1;
46                         if (pos < 0) return 1;
47                         file->memcursor += offset;
48                 }
49         }
50         return 0;
51 }
52
53 int logimage_fwrite(void *buffer, unsigned int size, unsigned int count, void *logfile)
54 {
55         struct _Log_Image_File_t_ *file = (struct _Log_Image_File_t_*) logfile;
56         if (file->file) return fwrite(buffer, size, count, file->file);
57         else { /*we're writing to memory*/
58                 /*do nothing as this isn't supported yet*/
59                 return count;
60         }
61 }
62
63 int logimage_fread(void *buffer, unsigned int size, unsigned int count, void *logfile)
64 {
65         struct _Log_Image_File_t_ *file = (struct _Log_Image_File_t_*) logfile;
66         if (file->file) return fread(buffer, size, count, file->file);
67         else { /*we're reading from memory*/
68                 int i;
69                 /*we convert ot uchar just on the off chance some platform can't handle
70                   pointer arithmetic with type (void*). */
71                 unsigned char *buf = (unsigned char *) buffer; 
72                 
73                 for (i=0; i<count; i++) {
74                         memcpy(buf, file->memcursor, size);
75                         file->memcursor += size;
76                         buf += size;
77                 }
78                 return count;
79         }
80 }