General housekeeping: Make plugin buffer functions take size_t * instead of int * to match the parameter type of the buffer functions called in the core. Get rid of unsafe int * <==> size_t * casting. Use ssize_t where int was used and size_t where unsigned int was used in the buffer calls to not alter signedness in the plugins. No API version change since it should only be an issue for 64-bit sim builds.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13233 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/codecs.c b/apps/codecs.c
index 1de8358..f5eb5db 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -63,7 +63,7 @@
 extern unsigned char codecbuf[];
 #endif
 
-extern void* plugin_get_audio_buffer(int *buffer_size);
+extern void* plugin_get_audio_buffer(size_t *buffer_size);
 
 struct codec_api ci_voice;
 
diff --git a/apps/codecs.h b/apps/codecs.h
index 5dfadcc..8f7d556 100644
--- a/apps/codecs.h
+++ b/apps/codecs.h
@@ -272,7 +272,7 @@
     int (*kbd_input)(char* buffer, int buflen);
     struct tm* (*get_time)(void);
     int  (*set_time)(const struct tm *tm);
-    void* (*plugin_get_audio_buffer)(int* buffer_size);
+    void* (*plugin_get_audio_buffer)(size_t* buffer_size);
     int (*round_value_to_list32)(unsigned long value,
                                  const unsigned long list[],
                                  int count,
diff --git a/apps/cuesheet.c b/apps/cuesheet.c
index 0d96eaf..970959b 100644
--- a/apps/cuesheet.c
+++ b/apps/cuesheet.c
@@ -312,7 +312,7 @@
 
 bool display_cuesheet_content(char* filename)
 {
-    unsigned int bufsize = 0;
+    size_t bufsize = 0;
     struct cuesheet *cue = (struct cuesheet *)plugin_get_buffer(&bufsize);
     if (!cue || bufsize < sizeof(struct cuesheet))
         return false;
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index 0617ed2..5f11499 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -947,7 +947,7 @@
             return false;
 
         /* get buffer space from the plugin buffer */
-        unsigned int buffersize = 0;
+        size_t buffersize = 0;
         char *wps_buffer = (char *)plugin_get_buffer(&buffersize);
 
         if (!wps_buffer)
diff --git a/apps/onplay.c b/apps/onplay.c
index 6aaa6e7..2912fc3 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -597,7 +597,8 @@
 /* Paste a file to a new directory. Will overwrite always. */
 static bool clipboard_pastefile(const char *src, const char *target, bool copy)
 {
-    int src_fd, target_fd, buffersize, size, bytesread, byteswritten;
+    int src_fd, target_fd;
+    ssize_t buffersize, size, bytesread, byteswritten;
     char *buffer;
     bool result = false;
 
diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c
index eaca81e..78ec231 100644
--- a/apps/playlist_viewer.c
+++ b/apps/playlist_viewer.c
@@ -276,7 +276,7 @@
                                  char* filename, bool reload)
 {
     char* buffer;
-    int buffer_size;
+    ssize_t buffer_size;
     bool is_playing = audio_status() & AUDIO_STATUS_PLAY;
 
     if (!filename && !is_playing)
@@ -294,7 +294,7 @@
         /* Viewing playlist on disk */
         char *dir, *file, *temp_ptr;
         char *index_buffer = NULL;
-        int  index_buffer_size = 0;
+        ssize_t index_buffer_size = 0;
 
         viewer->playlist = &temp_playlist;
 
diff --git a/apps/plugin.c b/apps/plugin.c
index a059a8d..0ce214c 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -667,7 +667,7 @@
 
 /* Returns a pointer to the portion of the plugin buffer that is not already
    being used.  If no plugin is loaded, returns the entire plugin buffer */
-void* plugin_get_buffer(int* buffer_size)
+void* plugin_get_buffer(size_t *buffer_size)
 {
     int buffer_pos;
 
@@ -692,10 +692,10 @@
    Playback gets stopped, to avoid conflicts.
    Talk buffer is stolen as well.
  */
-void* plugin_get_audio_buffer(int* buffer_size)
+void* plugin_get_audio_buffer(size_t *buffer_size)
 {
 #if CONFIG_CODEC == SWCODEC
-    return audio_get_buffer(true, (size_t *)buffer_size);
+    return audio_get_buffer(true, buffer_size);
 #else
     audio_stop();
     talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
diff --git a/apps/plugin.h b/apps/plugin.h
index f118260..2886b09 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -545,8 +545,8 @@
     int (*kbd_input)(char* buffer, int buflen);
     struct tm* (*get_time)(void);
     int  (*set_time)(const struct tm *tm);
-    void* (*plugin_get_buffer)(int* buffer_size);
-    void* (*plugin_get_audio_buffer)(int* buffer_size);
+    void* (*plugin_get_buffer)(size_t *buffer_size);
+    void* (*plugin_get_audio_buffer)(size_t *buffer_size);
     void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
 #ifdef IRAM_STEAL
     void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size,
@@ -653,8 +653,8 @@
 #endif /* PLUGIN */
 
 int plugin_load(const char* plugin, void* parameter);
-void* plugin_get_buffer(int *buffer_size);
-void* plugin_get_audio_buffer(int *buffer_size);
+void* plugin_get_buffer(size_t *buffer_size);
+void* plugin_get_audio_buffer(size_t *buffer_size);
 #ifdef IRAM_STEAL
 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
                       char *iedata, size_t iedata_size);
diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c
index c235900..08689d6 100644
--- a/apps/plugins/alpine_cdc.c
+++ b/apps/plugins/alpine_cdc.c
@@ -1143,7 +1143,7 @@
 #ifdef DEBUG
     int button;
 #endif
-    int stacksize;
+    ssize_t stacksize;
     void* stack;
 
     mbus_init(); /* init the M-Bus layer */
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c
index f481ee3..bb9e89e 100644
--- a/apps/plugins/cube.c
+++ b/apps/plugins/cube.c
@@ -552,7 +552,7 @@
     int t_disp = 0;
 #ifdef USE_GSLIB
     unsigned char *gbuf;
-    unsigned int gbuf_size = 0;
+    size_t gbuf_size = 0;
     bool mode_switch = true;
 #endif
 
diff --git a/apps/plugins/dict.c b/apps/plugins/dict.c
index 1ec9bce..4c12fa7 100644
--- a/apps/plugins/dict.c
+++ b/apps/plugins/dict.c
@@ -62,10 +62,10 @@
 
 /* global vars for pl_malloc() */
 void *bufptr;
-int bufleft;
+ssize_t bufleft;
 
 /* simple function to "allocate" memory in pluginbuffer. */
-void *pl_malloc(int size)
+void *pl_malloc(ssize_t size)
 {
     void *ptr;
     ptr = bufptr;
diff --git a/apps/plugins/doom/z_zone.c b/apps/plugins/doom/z_zone.c
index 552e321..1d0ac5b 100644
--- a/apps/plugins/doom/z_zone.c
+++ b/apps/plugins/doom/z_zone.c
@@ -231,7 +231,7 @@
 
 void Z_Init(void)
 {
-   unsigned int size;
+   size_t size;
 #ifdef INSTRUMENTED
    if (!(HEADER_SIZE >= sizeof(memblock_t) && MIN_RAM > LEAVE_ASIDE))
       I_Error("Z_Init: Sanity check failed");
diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c
index 4917bf6..915e9ae 100644
--- a/apps/plugins/fire.c
+++ b/apps/plugins/fire.c
@@ -37,7 +37,7 @@
 
 #ifndef HAVE_LCD_COLOR
 static unsigned char *gbuf;
-static unsigned int gbuf_size = 0;
+static size_t gbuf_size = 0;
 static unsigned char draw_buffer[8*LCD_WIDTH];
 #endif
 
diff --git a/apps/plugins/firmware_flash.c b/apps/plugins/firmware_flash.c
index a0fac42..c1cd3b2 100644
--- a/apps/plugins/firmware_flash.c
+++ b/apps/plugins/firmware_flash.c
@@ -880,7 +880,7 @@
     char default_filename[32];
     int button;
     int rc; /* generic return code */
-    int memleft;
+    ssize_t memleft;
     tCheckROM result;
     bool is_romless;
 
diff --git a/apps/plugins/grayscale.c b/apps/plugins/grayscale.c
index 61231af..6d3a83e 100644
--- a/apps/plugins/grayscale.c
+++ b/apps/plugins/grayscale.c
@@ -75,7 +75,7 @@
 static struct plugin_api* rb; /* global api struct pointer */
 static char pbuf[32];         /* global printf buffer */
 static unsigned char *gbuf;
-static unsigned int gbuf_size = 0;
+static size_t gbuf_size = 0;
 
 /**************************** main function ********************************/
 
diff --git a/apps/plugins/iriver_flash.c b/apps/plugins/iriver_flash.c
index 4a6002f..ea89f42 100644
--- a/apps/plugins/iriver_flash.c
+++ b/apps/plugins/iriver_flash.c
@@ -25,7 +25,7 @@
 #ifndef SIMULATOR /* only for target */
 
 unsigned char *audiobuf;
-int audiobuf_size;
+ssize_t audiobuf_size;
 
 #if defined(IRIVER_H120)
 #define PLATFORM_ID ID_IRIVER_H100
diff --git a/apps/plugins/iriverify.c b/apps/plugins/iriverify.c
index 91d890e..69c52f5 100644
--- a/apps/plugins/iriverify.c
+++ b/apps/plugins/iriverify.c
@@ -27,7 +27,7 @@
 
 static struct plugin_api* rb;
 
-int buf_size;
+ssize_t buf_size;
 static char *filename;
 static int readsize;
 static char *stringbuffer;
diff --git a/apps/plugins/jpeg.c b/apps/plugins/jpeg.c
index 038abdf..b52b3bf 100644
--- a/apps/plugins/jpeg.c
+++ b/apps/plugins/jpeg.c
@@ -1874,7 +1874,7 @@
 /* the remaining free part of the buffer for compressed+uncompressed images */
 unsigned char* buf_images;
 
-int buf_size, buf_images_size;
+ssize_t buf_size, buf_images_size;
 /* the root of the images, hereafter are decompresed ones */
 unsigned char* buf_root;
 int root_size;
diff --git a/apps/plugins/lib/overlay.c b/apps/plugins/lib/overlay.c
index edae366..7c2b899 100644
--- a/apps/plugins/lib/overlay.c
+++ b/apps/plugins/lib/overlay.c
@@ -47,7 +47,7 @@
                                unsigned char *filename, unsigned char *name)
 {
     int fd, readsize;
-    int audiobuf_size;
+    ssize_t audiobuf_size;
     unsigned char *audiobuf;
     static struct plugin_header header;
 
diff --git a/apps/plugins/mandelbrot.c b/apps/plugins/mandelbrot.c
index 824fc03..2c538fb 100644
--- a/apps/plugins/mandelbrot.c
+++ b/apps/plugins/mandelbrot.c
@@ -179,7 +179,7 @@
 
 #ifdef USEGSLIB
 static unsigned char *gbuf;
-static unsigned int gbuf_size = 0;
+static size_t  gbuf_size = 0;
 static unsigned char imgbuffer[LCD_HEIGHT];
 #else
 static fb_data imgbuffer[LCD_HEIGHT];
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index 5149104..9d114c9 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -146,7 +146,7 @@
 void *alloc(int size)
 {
     static char *offset = NULL;
-    static int totalSize = 0;
+    static ssize_t totalSize = 0;
     char *ret;
 
     int remainder = size % 4;
@@ -186,7 +186,7 @@
 void *alloc(int size)
 {
     static char *offset = NULL;
-    static int totalSize = 0;
+    static ssize_t totalSize = 0;
     char *ret;
 
 
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index d4a5c06..6b3ee92 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -1607,7 +1607,7 @@
 {
     int status = PLUGIN_ERROR; /* assume failure */
     void* audiobuf;
-    int audiosize;
+    ssize_t audiosize;
     int in_file;
     uint8_t* buffer;
     size_t file_remaining;
@@ -1652,7 +1652,7 @@
     buffer_size = audiosize - (PCMBUFFER_SIZE+PCMBUFFER_GUARD_SIZE+
                                MPABUF_SIZE+LIBMPEG2BUFFER_SIZE);
 
-    DEBUGF("audiosize=%d, buffer_size=%ld\n",audiosize,buffer_size);
+    DEBUGF("audiosize=%ld, buffer_size=%ld\n",audiosize,buffer_size);
     buffer = mpeg2_malloc(buffer_size,-1);
 
     if (buffer == NULL)
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c
index d5decd1..09249d9 100644
--- a/apps/plugins/plasma.c
+++ b/apps/plugins/plasma.c
@@ -45,7 +45,7 @@
 static unsigned char colours[256]; /* Smooth transition of shades */
 static unsigned char graybuffer[LCD_HEIGHT*LCD_WIDTH]; /* off screen buffer */
 static unsigned char *gbuf;
-static unsigned int gbuf_size = 0;
+static size_t        gbuf_size = 0;
 #endif
 static unsigned char sp1, sp2, sp3, sp4; /* Speed of plasma */
 static int plasma_frequency;
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c
index e300675..2afaf4d 100644
--- a/apps/plugins/random_folder_advance_config.c
+++ b/apps/plugins/random_folder_advance_config.c
@@ -27,7 +27,7 @@
 static int lasttick;
 #define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat"
 char *buffer = NULL;
-int buffer_size;
+ssize_t buffer_size;
 struct file_format {
     int count;
     char folder[][MAX_PATH];
diff --git a/apps/plugins/rockbox_flash.c b/apps/plugins/rockbox_flash.c
index 8edfd01..86e62eb 100644
--- a/apps/plugins/rockbox_flash.c
+++ b/apps/plugins/rockbox_flash.c
@@ -645,7 +645,7 @@
     int rc; /* generic return code */
     UINT32 space, aligned_size, true_size;
     UINT8* pos;
-    int memleft;
+    ssize_t memleft;
     UINT32 crc;
     bool show_greet = false;
     
@@ -849,7 +849,7 @@
     int rc; /* generic return code */
     UINT32 space, aligned_size, true_size;
     UINT8* pos;
-    int memleft;
+    ssize_t memleft;
     UINT32 crc;
 
     /* this can only work if Rockbox runs in DRAM, not flash ROM */
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c
index 3fbe1fd..cefa0e4 100644
--- a/apps/plugins/rockboy/rockboy.c
+++ b/apps/plugins/rockboy/rockboy.c
@@ -44,7 +44,7 @@
 
 void *audio_bufferbase;
 void *audio_bufferpointer;
-unsigned int audio_buffer_free;
+size_t audio_buffer_free;
 
 void *my_malloc(size_t size)
 {
@@ -194,13 +194,13 @@
     if(rb->audio_status())
     {
         audio_bufferbase = audio_bufferpointer
-            = rb->plugin_get_buffer((int *)&audio_buffer_free);
+            = rb->plugin_get_buffer(&audio_buffer_free);
         plugbuf=true;
     }
     else
     {
         audio_bufferbase = audio_bufferpointer
-            = rb->plugin_get_audio_buffer((int *)&audio_buffer_free);
+            = rb->plugin_get_audio_buffer(&audio_buffer_free);
         plugbuf=false;
     }
 #if MEM <= 8 && !defined(SIMULATOR)
diff --git a/apps/plugins/searchengine/searchengine.c b/apps/plugins/searchengine/searchengine.c
index 2687bd9..62d3a91 100644
--- a/apps/plugins/searchengine/searchengine.c
+++ b/apps/plugins/searchengine/searchengine.c
@@ -25,7 +25,7 @@
 
 void *audio_bufferbase;
 void *audio_bufferpointer;
-unsigned int audio_buffer_free;
+size_t audio_buffer_free;
 struct plugin_api* rb;
 int w, h, y;
 
diff --git a/apps/plugins/snake2.c b/apps/plugins/snake2.c
index cd4037a..54a88b4 100644
--- a/apps/plugins/snake2.c
+++ b/apps/plugins/snake2.c
@@ -327,7 +327,7 @@
 {
     int linecnt = 0;
     int fd;
-    int size;
+    ssize_t size;
     char buf[64]; /* Larger than WIDTH, to allow for whitespace after the
                      lines */
 
diff --git a/apps/plugins/sort.c b/apps/plugins/sort.c
index 79b5400..3d348c1 100644
--- a/apps/plugins/sort.c
+++ b/apps/plugins/sort.c
@@ -59,7 +59,7 @@
 
 static struct plugin_api* rb;
 
-int buf_size;
+ssize_t buf_size;
 static char *filename;
 static int num_entries;
 static char **pointers;
diff --git a/apps/plugins/splitedit.c b/apps/plugins/splitedit.c
index a44087e..7dd6be0 100644
--- a/apps/plugins/splitedit.c
+++ b/apps/plugins/splitedit.c
@@ -573,7 +573,7 @@
     unsigned char *buffer;
     unsigned int i = 0;
     ssize_t bytes_read = 1; /* ensure the for loop is executed */
-    unsigned int buffer_size;
+    size_t buffer_size;
     buffer = rb->plugin_get_buffer(&buffer_size);
 
     for (i = 0; i < bytes && bytes_read > 0; i += bytes_read)
diff --git a/apps/plugins/test_disk.c b/apps/plugins/test_disk.c
index e302a62..44cee39 100644
--- a/apps/plugins/test_disk.c
+++ b/apps/plugins/test_disk.c
@@ -32,7 +32,7 @@
 
 static struct plugin_api* rb;
 static unsigned char* audiobuf;
-static int audiobufsize;
+static ssize_t audiobufsize;
 
 static unsigned short frnd_buffer;
 static int line = 0;
diff --git a/apps/plugins/vbrfix.c b/apps/plugins/vbrfix.c
index 73409eb..e3b74cb 100644
--- a/apps/plugins/vbrfix.c
+++ b/apps/plugins/vbrfix.c
@@ -22,8 +22,8 @@
 
 static struct plugin_api* rb;
 
-static char *audiobuf;
-static int audiobuflen;
+static char   *audiobuf;
+static ssize_t audiobuflen;
 
 static void xingupdate(int percent)
 {
diff --git a/apps/plugins/wav2wv.c b/apps/plugins/wav2wv.c
index 34f0317..a889bb8 100644
--- a/apps/plugins/wav2wv.c
+++ b/apps/plugins/wav2wv.c
@@ -38,7 +38,7 @@
 }
 
 static char *audiobuf;
-static int audiobuflen;
+static ssize_t audiobuflen;
 
 static struct wav_header {
     char ckID [4];                      /* RIFF chuck header */
diff --git a/apps/plugins/wavplay.c b/apps/plugins/wavplay.c
index faa5b08..e814ccb 100644
--- a/apps/plugins/wavplay.c
+++ b/apps/plugins/wavplay.c
@@ -3138,7 +3138,7 @@
 static struct plugin_api *rb;
 
 static unsigned char *aud_buf;
-static int aud_size;
+static ssize_t aud_size;
 static unsigned char *plug_buf;
 
 static void (*pcm_callback)(unsigned char**, int*) = NULL;
@@ -3649,7 +3649,7 @@
 /* plugin entry point */
 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
 {
-	int buf_size;
+	ssize_t buf_size;
 
     rb = api;
     
diff --git a/apps/plugins/wavview.c b/apps/plugins/wavview.c
index b56a379..f399e05 100644
--- a/apps/plugins/wavview.c
+++ b/apps/plugins/wavview.c
@@ -60,7 +60,7 @@
 
 /* global vars */
 static char *audiobuf;
-static int audiobuflen;
+static ssize_t audiobuflen;
 static uint32_t mempeakcount = 0;
 static uint32_t filepeakcount = 0;
 static uint32_t fppmp = 0; /* file peaks per mem peaks */
diff --git a/apps/plugins/zxbox/helpers.c b/apps/plugins/zxbox/helpers.c
index c176c00..d6b25a2 100644
--- a/apps/plugins/zxbox/helpers.c
+++ b/apps/plugins/zxbox/helpers.c
@@ -19,7 +19,7 @@
 void *my_malloc(size_t size)
 {
     static char *offset = NULL;
-    static int totalSize = 0;
+    static ssize_t totalSize = 0;
     char *ret;
 
     int remainder = size % 4;
diff --git a/apps/plugins/zxbox/zxbox.c b/apps/plugins/zxbox/zxbox.c
index b85dc01..1faec08 100644
--- a/apps/plugins/zxbox/zxbox.c
+++ b/apps/plugins/zxbox/zxbox.c
@@ -52,7 +52,7 @@
 
 #ifdef USE_GRAY
 static unsigned char *gbuf;
-static unsigned int gbuf_size = 0;
+static size_t         gbuf_size = 0;
 #endif
 
 long video_frames IBSS_ATTR = 0 ;