Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 50465) +++ apps/app_voicemail.c (working copy) @@ -848,6 +848,7 @@ SQLSMALLINT decimaldigits; SQLSMALLINT nullable; SQLULEN colsize; + SQLULEN colsize2; FILE *f=NULL; char rowdata[80]; char fn[PATH_MAX]; @@ -931,8 +932,12 @@ goto yuck; } if (!strcasecmp(coltitle, "recording")) { + + ast_log(LOG_NOTICE, "Column %d: colsize = %d, collen = %d, datatype = %d\n",x + 1,colsize,collen,datatype); off_t offset; - res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize); + res = SQLGetData(stmt, x + 1, SQL_C_BINARY, rowdata, 0, &colsize); + ast_log(LOG_NOTICE, "res = %d; colsize = %d\n",res,colsize); + fdlen = colsize; if (fd > -1) { char tmp[1]=""; @@ -943,15 +948,19 @@ continue; } /* Read out in small chunks */ + ast_log(LOG_NOTICE, "Proceeding with reading out the data in small chunks\n"); for (offset = 0; offset < colsize; offset += CHUNKSIZE) { - /* +1 because SQLGetData likes null-terminating binary data */ - if ((fdm = mmap(NULL, CHUNKSIZE + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == -1) { + ast_log(LOG_NOTICE, "Offset = %d\n",offset); + if ((fdm = mmap(NULL, CHUNKSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == (void *)-1) { ast_log(LOG_WARNING, "Could not mmap the output file: %s (%d)\n", strerror(errno), errno); + /* Do we need this unlink here? I added it because I think we do */ + unlink(full_fn); SQLFreeHandle(SQL_HANDLE_STMT, stmt); goto yuck; } else { - res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, CHUNKSIZE + 1, NULL); - munmap(fdm, 0); + res = SQLGetData(stmt, x + 1, SQL_C_BINARY, fdm, CHUNKSIZE, &colsize2); + ast_log(LOG_NOTICE, "res = %d, colsize2 = \n",res,colsize2); + munmap(fdm, CHUNKSIZE); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); unlink(full_fn);