version 1.56, 2007/11/23 05:43:23 |
version 1.57, 2009/02/03 00:39:23 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/array.c,v 1.55 2006/10/26 10:49:16 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/builtin/array.c,v 1.56 2007/11/23 05:43:23 ohara Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
Line 459 void Pnewbytearray(NODE arg,BYTEARRAY *rp) |
|
Line 459 void Pnewbytearray(NODE arg,BYTEARRAY *rp) |
|
|
|
ac = argc(arg); |
ac = argc(arg); |
if ( ac == 1 ) { |
if ( ac == 1 ) { |
/* ARG0(arg) must be a filename */ |
if ( !OID((Obj)ARG0(arg)) ) error("newbytearray : invalid argument"); |
asir_assert(ARG0(arg),O_STR,"newbytearray"); |
switch ( OID((Obj)ARG0(arg)) ) { |
fname = BDY((STRING)ARG0(arg)); |
case O_STR: |
fp = fopen(fname,"rb"); |
fname = BDY((STRING)ARG0(arg)); |
if ( !fp ) error("newbytearray : fopen failed"); |
fp = fopen(fname,"rb"); |
if ( stat(fname,&sbuf) < 0 ) error("newbytearray : stat failed"); |
if ( !fp ) error("newbytearray : fopen failed"); |
len = sbuf.st_size; |
if ( stat(fname,&sbuf) < 0 ) |
MKBYTEARRAY(array,len); |
error("newbytearray : stat failed"); |
fread(BDY(array),len,sizeof(char),fp); |
len = sbuf.st_size; |
|
MKBYTEARRAY(array,len); |
|
fread(BDY(array),len,sizeof(char),fp); |
|
break; |
|
case O_N: |
|
if ( !RATN(ARG0(arg)) ) |
|
error("newbytearray : invalid argument"); |
|
len = QTOS((Q)ARG0(arg)); |
|
if ( len < 0 ) |
|
error("newbytearray : invalid size"); |
|
MKBYTEARRAY(array,len); |
|
break; |
|
default: |
|
error("newbytearray : invalid argument"); |
|
} |
} else if ( ac == 2 ) { |
} else if ( ac == 2 ) { |
asir_assert(ARG0(arg),O_N,"newbytearray"); |
asir_assert(ARG0(arg),O_N,"newbytearray"); |
len = QTOS((Q)ARG0(arg)); |
len = QTOS((Q)ARG0(arg)); |