a.out format does not support many .section directives
[platform/upstream/flac.git] / src / libFLAC / ogg_helper.c
index edac05d..0817368 100644 (file)
@@ -1,5 +1,5 @@
 /* libFLAC - Free Lossless Audio Codec
- * Copyright (C) 2004,2005,2006  Josh Coalson
+ * Copyright (C) 2004,2005,2006,2007,2008,2009  Josh Coalson
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <stdlib.h> /* for malloc() */
 #include <string.h> /* for memcmp(), memcpy() */
 #include "FLAC/assert.h"
+#include "share/alloc.h"
 #include "private/ogg_helper.h"
 #include "protected/stream_encoder.h"
 
 
-static FLAC__bool full_read_(FLAC__StreamEncoder *encoder, FLAC__byte *buffer, unsigned bytes, FLAC__StreamEncoderReadCallback read_callback, void *client_data)
+static FLAC__bool full_read_(FLAC__StreamEncoder *encoder, FLAC__byte *buffer, size_t bytes, FLAC__StreamEncoderReadCallback read_callback, void *client_data)
 {
        while(bytes > 0) {
-               unsigned bytes_read = bytes;
+               size_t bytes_read = bytes;
                switch(read_callback(encoder, buffer, &bytes_read, client_data)) {
                        case FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE:
                                bytes -= bytes_read;
@@ -112,7 +113,7 @@ FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
        }
 
        /* allocate space for the page header */
-       if(0 == (page->header = (unsigned char *)malloc(OGG_MAX_HEADER_LEN))) {
+       if(0 == (page->header = (unsigned char *)safe_malloc_(OGG_MAX_HEADER_LEN))) {
                encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
                return false;
        }
@@ -150,11 +151,11 @@ FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
                        }
                }
 
-               page->body_len = 255 * i + page->header[i];
+               page->body_len = 255 * i + page->header[i + OGG_HEADER_FIXED_PORTION_LEN];
        }
 
        /* allocate space for the page body */
-       if(0 == (page->body = (unsigned char *)malloc(page->body_len))) {
+       if(0 == (page->body = (unsigned char *)safe_malloc_(page->body_len))) {
                encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
                return false;
        }
@@ -199,6 +200,10 @@ FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
                encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
                return false;
        }
+       if(write_callback((FLAC__StreamEncoder*)encoder, page->body, page->body_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
+               encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
+               return false;
+       }
 
        return true;
 }