1 /* -*-C++-*- $NetBSD: file.cpp,v 1.2 2001/05/08 18:51:22 uch Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <console.h> 40 #include <file.h> 41 #include <file_fat.h> 42 #include <file_http.h> 43 #include <file_ufs.h> 44 45 FileManager::FileManager(Console *&cons, enum FileOps ops) 46 : File(cons) 47 { 48 // File System 49 switch(ops) { 50 default: 51 case FILE_UFS: 52 _file = new UfsFile(_cons); 53 break; 54 case FILE_FAT: 55 _file = new FatFile(_cons); 56 break; 57 case FILE_HTTP: 58 _file = new HttpFile(_cons); 59 } 60 61 // GZIP set magic header 62 _gz_magic[0] = 0x1f; _gz_magic[1] = 0x8b; 63 memset(_inbuf, 0, Z_BUFSIZE); 64 _reset(); 65 } 66 67 // 68 // UNICODE util. 69 // 70 BOOL 71 File::_to_ascii(char *m, const TCHAR *w, size_t mlen) 72 { 73 size_t len = WideCharToMultiByte(CP_ACP, 0, w, wcslen(w), 0, 0, 0, 0); 74 if (len + 1 > mlen) { 75 DPRINTF((TEXT("buffer insufficeint. %d > %d\n"), 76 len + 1, mlen)); 77 return FALSE; 78 } 79 int ret = WideCharToMultiByte(CP_ACP, 0, w, len, m, len, 0, 0); 80 if (ret == 0) { 81 DPRINTF((TEXT("can't convert to ASCII.\n"))); 82 return FALSE; 83 } 84 m[len] = '\0'; 85 86 return TRUE; 87 } 88