value sys_open(value path, value flags, value perm) /* ML */ { int ret; #ifdef macintosh extern void set_file_type (char *name, long type); #if defined(THINK_C) || defined(__MWERKS__) # define FILE_NAME_SIZE 256 char filename_temp[FILE_NAME_SIZE]; char *expanded; extern char *unix_to_mac_filename(char *, char *, int); expanded = unix_to_mac_filename(String_val(path), filename_temp, FILE_NAME_SIZE); if (expanded == NULL) ret = -1; else ret = open(expanded, convert_flag_list(flags, sys_open_flags)); if ( ret != -1 && convert_flag_list (flags, sys_text_flags) && convert_flag_list (flags, sys_write_flags)) set_file_type (expanded, 'TEXT'); #else ret = open(String_val(path), convert_flag_list(flags, sys_open_flags)); if (ret != -1 && convert_flag_list (flags, sys_text_flags)) set_file_type (String_val (path), 'TEXT'); #endif #else ret = open(String_val(path), convert_flag_list(flags, sys_open_flags), Int_val(perm)); #endif if (ret == -1) sys_error(String_val(path)); return Val_long(ret); }
/* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and output the encoded block to the zip file. This function * returns the total compressed length (in bytes) for the file so far. */ ulg flush_block(TState &state,char *buf, ulg stored_len, int eof) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex; /* index of last bit length code of non zero freq */ state.ts.flag_buf[state.ts.last_flags] = state.ts.flags; /* Save the flags for the last 8 items */ /* Check if the file is ascii or binary */ if (*state.ts.file_type == (ush)UNKNOWN) set_file_type(state); /* Construct the literal and distance trees */ build_tree(state,(tree_desc *)(&state.ts.l_desc)); Trace("\nlit data: dyn %ld, stat %ld", state.ts.opt_len, state.ts.static_len); build_tree(state,(tree_desc *)(&state.ts.d_desc)); Trace("\ndist data: dyn %ld, stat %ld", state.ts.opt_len, state.ts.static_len); /* At this point, opt_len and static_len are the total bit lengths of * the compressed block data, excluding the tree representations. */ /* Build the bit length tree for the above two trees, and get the index * in bl_order of the last bit length code to send. */ max_blindex = build_bl_tree(state); /* Determine the best encoding. Compute first the block length in bytes */ opt_lenb = (state.ts.opt_len+3+7)>>3; static_lenb = (state.ts.static_len+3+7)>>3; state.ts.input_len += stored_len; /* for debugging only */ Trace("\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ", opt_lenb, state.ts.opt_len, static_lenb, state.ts.static_len, stored_len, state.ts.last_lit, state.ts.last_dist); if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
int __open_file(const char * name, __file_modes mode, __file_handle * handle) { FSSpec spec; OSErr ioResult; HParamBlockRec pb; ioResult = __path2fss(name, &spec); if (ioResult) gSqueakFileLastError = ioResult; if (__system7present()) /* mm 980424 */ { /* mm 980424 */ Boolean targetIsFolder, wasAliased; /* mm 980424 */ ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); /* mm 980424 */ } /* mm 980424 */ if (ioResult && (ioResult != fnfErr || mode.open_mode == __must_exist)) return(__io_error); #if TARGET_API_MAC_CARBON if (ioResult) { CFStringRef filePath; CFURLRef sillyThing, sillyThing2; FSRef parentFSRef; short int fileRefNum; OSErr err; UniChar buffer[1024]; long tokenLength; filePath = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)name,strlen(name),gCurrentVMEncoding,false); if (filePath == nil) return __io_error; sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false); CFRelease(filePath); sillyThing2 = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault,sillyThing); err = CFURLGetFSRef(sillyThing2,&parentFSRef); if (err == 0) { CFRelease(sillyThing); CFRelease(sillyThing2); return fnfErr; } filePath = CFURLCopyLastPathComponent(sillyThing); tokenLength = CFStringGetLength(filePath); if (tokenLength > 1024) { CFRelease(filePath); CFRelease(sillyThing); CFRelease(sillyThing2); return(__io_error); } CFStringGetCharacters(filePath,CFRangeMake(0,tokenLength),buffer); CFRelease(filePath); CFRelease(sillyThing); CFRelease(sillyThing2); ioResult = FSCreateFileUnicode(&parentFSRef,tokenLength,buffer,kFSCatInfoNone,NULL,NULL,&spec); if (ioResult) gSqueakFileLastError = ioResult; if (ioResult) return(__io_error); pb.ioParam.ioNamePtr = spec.name; pb.ioParam.ioVRefNum = spec.vRefNum; pb.ioParam.ioPermssn = (mode.io_mode == __read) ? fsRdPerm : fsRdWrPerm; pb.ioParam.ioMisc = 0; pb.fileParam.ioFVersNum = 0; pb.fileParam.ioDirID = spec.parID; set_file_type(&spec, mode.binary_io); ioResult = PBHOpenDFSync(&pb); /* HH 10/25/97 was PBHOpenSync */ if (ioResult) return(__io_error); *handle = pb.ioParam.ioRefNum; return(__no_io_error); } #endif pb.ioParam.ioNamePtr = spec.name; pb.ioParam.ioVRefNum = spec.vRefNum; pb.ioParam.ioPermssn = (mode.io_mode == __read) ? fsRdPerm : fsRdWrPerm; pb.ioParam.ioMisc = 0; pb.fileParam.ioFVersNum = 0; pb.fileParam.ioDirID = spec.parID; if (ioResult) { if (!(ioResult = PBHCreateSync(&pb))) { if (ioResult) gSqueakFileLastError = ioResult; set_file_type(&spec, mode.binary_io); ioResult = PBHOpenDFSync(&pb); /* HH 10/25/97 was PBHOpenSync */ if (ioResult) gSqueakFileLastError = ioResult; } } else { if (!(ioResult = PBHOpenDFSync(&pb)) && mode.open_mode == __create_or_truncate) /* HH 10/25/97 was PBHOpenSync */ { pb.ioParam.ioMisc = 0; ioResult = PBSetEOFSync((ParmBlkPtr) &pb); if (ioResult) gSqueakFileLastError = ioResult; if (ioResult) PBCloseSync((ParmBlkPtr) &pb); } else { if (ioResult) gSqueakFileLastError = ioResult; } } if (ioResult) return(__io_error); *handle = pb.ioParam.ioRefNum; return(__no_io_error); }