summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/libtta/ttadec.c18
-rw-r--r--apps/language.c2
-rw-r--r--apps/metadata.h2
-rw-r--r--apps/tree.c4
-rw-r--r--apps/tree.h8
-rw-r--r--firmware/export/load_code.h8
-rw-r--r--firmware/include/file.h29
-rw-r--r--firmware/libc/include/fcntl.h40
-rw-r--r--firmware/load_code.c8
-rw-r--r--uisimulator/common/io.c9
10 files changed, 85 insertions, 43 deletions
diff --git a/apps/codecs/libtta/ttadec.c b/apps/codecs/libtta/ttadec.c
index 9d53a327f2..cdaffcd9d9 100644
--- a/apps/codecs/libtta/ttadec.c
+++ b/apps/codecs/libtta/ttadec.c
@@ -77,7 +77,7 @@ static unsigned char *bitpos IBSS_ATTR;
77/********************* rockbox helper functions *************************/ 77/********************* rockbox helper functions *************************/
78 78
79/* emulate stdio functions */ 79/* emulate stdio functions */
80static int fread(void *ptr, size_t size, size_t nobj) 80static size_t tta_fread(void *ptr, size_t size, size_t nobj)
81{ 81{
82 size_t read_size; 82 size_t read_size;
83 unsigned char *buffer = ci->request_buffer(&read_size, size * nobj); 83 unsigned char *buffer = ci->request_buffer(&read_size, size * nobj);
@@ -90,7 +90,7 @@ static int fread(void *ptr, size_t size, size_t nobj)
90 return read_size; 90 return read_size;
91} 91}
92 92
93static int fseek(long offset, int origin) 93static int tta_fseek(long offset, int origin)
94{ 94{
95 switch (origin) 95 switch (origin)
96 { 96 {
@@ -129,7 +129,7 @@ crc32 (unsigned char *buffer, unsigned int len) {
129#define GET_BINARY(value, bits) \ 129#define GET_BINARY(value, bits) \
130 while (bit_count < bits) { \ 130 while (bit_count < bits) { \
131 if (bitpos == iso_buffers_end) { \ 131 if (bitpos == iso_buffers_end) { \
132 if (!fread(isobuffers, 1, ISO_BUFFERS_SIZE)) { \ 132 if (!tta_fread(isobuffers, 1, ISO_BUFFERS_SIZE)) { \
133 ttainfo->STATE = READ_ERROR; \ 133 ttainfo->STATE = READ_ERROR; \
134 return -1; \ 134 return -1; \
135 } \ 135 } \
@@ -149,7 +149,7 @@ crc32 (unsigned char *buffer, unsigned int len) {
149 value = 0; \ 149 value = 0; \
150 while (!(bit_cache ^ bit_mask[bit_count])) { \ 150 while (!(bit_cache ^ bit_mask[bit_count])) { \
151 if (bitpos == iso_buffers_end) { \ 151 if (bitpos == iso_buffers_end) { \
152 if (!fread(isobuffers, 1, ISO_BUFFERS_SIZE)) { \ 152 if (!tta_fread(isobuffers, 1, ISO_BUFFERS_SIZE)) { \
153 ttainfo->STATE = READ_ERROR; \ 153 ttainfo->STATE = READ_ERROR; \
154 return -1; \ 154 return -1; \
155 } \ 155 } \
@@ -207,7 +207,7 @@ static int done_buffer_read(void) {
207 207
208 if (rbytes < sizeof(int)) { 208 if (rbytes < sizeof(int)) {
209 ci->memcpy(isobuffers, bitpos, 4); 209 ci->memcpy(isobuffers, bitpos, 4);
210 if (!fread(isobuffers + rbytes, 1, ISO_BUFFERS_SIZE - rbytes)) 210 if (!tta_fread(isobuffers + rbytes, 1, ISO_BUFFERS_SIZE - rbytes))
211 return -1; 211 return -1;
212 bitpos = isobuffers; 212 bitpos = isobuffers;
213 } 213 }
@@ -249,10 +249,10 @@ int set_tta_info (tta_info *info)
249 ci->memset (info, 0, sizeof(tta_info)); 249 ci->memset (info, 0, sizeof(tta_info));
250 250
251 /* skip id3v2 tags */ 251 /* skip id3v2 tags */
252 fseek(ci->id3->id3v2len, SEEK_SET); 252 tta_fseek(ci->id3->id3v2len, SEEK_SET);
253 253
254 /* read TTA header */ 254 /* read TTA header */
255 if (fread (&ttahdr, 1, sizeof (ttahdr)) == 0) { 255 if (tta_fread (&ttahdr, 1, sizeof (ttahdr)) == 0) {
256 info->STATE = READ_ERROR; 256 info->STATE = READ_ERROR;
257 return -1; 257 return -1;
258 } 258 }
@@ -374,7 +374,7 @@ int set_position (unsigned int pos, enum tta_seek_type type)
374 return -1; 374 return -1;
375 } 375 }
376 seek_pos = ttainfo->DATAPOS + seek_table[data_pos = pos]; 376 seek_pos = ttainfo->DATAPOS + seek_table[data_pos = pos];
377 if (fseek(seek_pos, SEEK_SET) < 0) { 377 if (tta_fseek(seek_pos, SEEK_SET) < 0) {
378 ttainfo->STATE = READ_ERROR; 378 ttainfo->STATE = READ_ERROR;
379 return -1; 379 return -1;
380 } 380 }
@@ -418,7 +418,7 @@ int player_init (tta_info *info) {
418 } 418 }
419 419
420 /* read seek table */ 420 /* read seek table */
421 if (!fread(seek_table, st_size, 1)) { 421 if (!tta_fread(seek_table, st_size, 1)) {
422 ttainfo->STATE = READ_ERROR; 422 ttainfo->STATE = READ_ERROR;
423 return -1; 423 return -1;
424 } 424 }
diff --git a/apps/language.c b/apps/language.c
index fea4fb3264..39903c4346 100644
--- a/apps/language.c
+++ b/apps/language.c
@@ -19,7 +19,7 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#include <file.h> 22#include "file.h"
23 23
24#include "language.h" 24#include "language.h"
25#include "lang.h" 25#include "lang.h"
diff --git a/apps/metadata.h b/apps/metadata.h
index b73d92b83f..39da30e1a5 100644
--- a/apps/metadata.h
+++ b/apps/metadata.h
@@ -23,8 +23,8 @@
23#define _METADATA_H 23#define _METADATA_H
24 24
25#include <stdbool.h> 25#include <stdbool.h>
26#include "file.h"
27#include "config.h" 26#include "config.h"
27#include "file.h"
28 28
29 29
30/* Audio file types. */ 30/* Audio file types. */
diff --git a/apps/tree.c b/apps/tree.c
index 4d915ca3b8..730c59f611 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -511,13 +511,13 @@ void resume_directory(const char *dir)
511 511
512/* Returns the current working directory and also writes cwd to buf if 512/* Returns the current working directory and also writes cwd to buf if
513 non-NULL. In case of error, returns NULL. */ 513 non-NULL. In case of error, returns NULL. */
514char *getcwd(char *buf, size_t size) 514char *getcwd(char *buf, getcwd_size_t size)
515{ 515{
516 if (!buf) 516 if (!buf)
517 return tc.currdir; 517 return tc.currdir;
518 else if (size) 518 else if (size)
519 { 519 {
520 if (strlcpy(buf, tc.currdir, size) < size) 520 if ((getcwd_size_t)strlcpy(buf, tc.currdir, size) < size)
521 return buf; 521 return buf;
522 } 522 }
523 /* size == 0, or truncation in strlcpy */ 523 /* size == 0, or truncation in strlcpy */
diff --git a/apps/tree.h b/apps/tree.h
index e33fee00d7..993d1b4569 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -79,7 +79,13 @@ void set_current_file(char *path);
79int rockbox_browse(const char *root, int dirfilter); 79int rockbox_browse(const char *root, int dirfilter);
80bool create_playlist(void); 80bool create_playlist(void);
81void resume_directory(const char *dir); 81void resume_directory(const char *dir);
82char *getcwd(char *buf, size_t size); 82#ifdef WIN32
83/* it takes an int on windows */
84#define getcwd_size_t int
85#else
86#define getcwd_size_t size_t
87#endif
88char *getcwd(char *buf, getcwd_size_t size);
83void reload_directory(void); 89void reload_directory(void);
84bool check_rockboxdir(void); 90bool check_rockboxdir(void);
85struct tree_context* tree_get_context(void); 91struct tree_context* tree_get_context(void);
diff --git a/firmware/export/load_code.h b/firmware/export/load_code.h
index f4fa8f9b46..e37af786df 100644
--- a/firmware/export/load_code.h
+++ b/firmware/export/load_code.h
@@ -42,7 +42,13 @@ static inline void lc_close(void *handle) { (void)handle; }
42 42
43/* don't call these directly for loading code 43/* don't call these directly for loading code
44 * they're to be wrapped by platform specific functions */ 44 * they're to be wrapped by platform specific functions */
45extern void *_lc_open(const char *filename, char *buf, size_t buf_size); 45#ifdef WIN32
46/* windows' LoadLibrary can only handle ucs2, no utf-8 */
47#define _lc_open_char wchar_t
48#else
49#define _lc_open_char char
50#endif
51extern void *_lc_open(const _lc_open_char *filename, char *buf, size_t buf_size);
46extern void *_lc_get_header(void *handle); 52extern void *_lc_get_header(void *handle);
47extern void _lc_close(void *handle); 53extern void _lc_close(void *handle);
48 54
diff --git a/firmware/include/file.h b/firmware/include/file.h
index a9d1d05a11..7799f3d625 100644
--- a/firmware/include/file.h
+++ b/firmware/include/file.h
@@ -25,31 +25,19 @@
25#include <sys/types.h> 25#include <sys/types.h>
26#include "config.h" 26#include "config.h"
27#include "gcc_extensions.h" 27#include "gcc_extensions.h"
28#include <fcntl.h>
29#ifdef WIN32
30/* this has SEEK_SET et al */
31#include <stdio.h>
32#endif
33
28 34
29#undef MAX_PATH /* this avoids problems when building simulator */ 35#undef MAX_PATH /* this avoids problems when building simulator */
30#define MAX_PATH 260 36#define MAX_PATH 260
31#define MAX_OPEN_FILES 11 37#define MAX_OPEN_FILES 11
32 38
33#ifndef SEEK_SET 39#if !defined(PLUGIN) && !defined(CODEC)
34#define SEEK_SET 0 40#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
35#endif
36#ifndef SEEK_CUR
37#define SEEK_CUR 1
38#endif
39#ifndef SEEK_END
40#define SEEK_END 2
41#endif
42
43#ifndef O_RDONLY
44#define O_RDONLY 0
45#define O_WRONLY 1
46#define O_RDWR 2
47#define O_CREAT 4
48#define O_APPEND 8
49#define O_TRUNC 0x10
50#endif
51
52#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(PLUGIN) && !defined(CODEC)
53#define open(x, ...) sim_open(x, __VA_ARGS__) 41#define open(x, ...) sim_open(x, __VA_ARGS__)
54#define creat(x,m) sim_creat(x,m) 42#define creat(x,m) sim_creat(x,m)
55#define remove(x) sim_remove(x) 43#define remove(x) sim_remove(x)
@@ -96,4 +84,5 @@ extern int ftruncate(int fd, off_t length);
96extern off_t filesize(int fd); 84extern off_t filesize(int fd);
97extern int release_files(int volume); 85extern int release_files(int volume);
98int fdprintf (int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); 86int fdprintf (int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
87#endif /* !CODEC && !PLUGIN */
99#endif 88#endif
diff --git a/firmware/libc/include/fcntl.h b/firmware/libc/include/fcntl.h
new file mode 100644
index 0000000000..34740c9ca2
--- /dev/null
+++ b/firmware/libc/include/fcntl.h
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __FCNTL_H__
23#define __FCNTL_H__
24
25#ifndef O_RDONLY
26#define O_RDONLY 0
27#define O_WRONLY 1
28#define O_RDWR 2
29#define O_CREAT 4
30#define O_APPEND 8
31#define O_TRUNC 0x10
32#endif
33
34#ifndef SEEK_SET
35#define SEEK_SET 0
36#define SEEK_CUR 1
37#define SEEK_END 2
38#endif
39
40#endif /* __FCNTL_H__ */
diff --git a/firmware/load_code.c b/firmware/load_code.c
index 9e8e71f9af..75bac8b2ac 100644
--- a/firmware/load_code.c
+++ b/firmware/load_code.c
@@ -80,13 +80,12 @@ static inline char *_dlerror(void)
80#else 80#else
81/* unix */ 81/* unix */
82#include <dlfcn.h> 82#include <dlfcn.h>
83#define O_BINARY 0
84#endif 83#endif
85#include <stdio.h> 84#include <stdio.h>
86#include "rbpaths.h" 85#include "rbpaths.h"
87#include "general.h" 86#include "general.h"
88 87
89void * _lc_open(const char *filename, char *buf, size_t buf_size) 88void * _lc_open(const _lc_open_char *filename, char *buf, size_t buf_size)
90{ 89{
91 (void)buf; 90 (void)buf;
92 (void)buf_size; 91 (void)buf_size;
@@ -116,14 +115,13 @@ void *lc_open_from_mem(void *addr, size_t blob_size)
116 char name[MAX_PATH]; 115 char name[MAX_PATH];
117 const char *_name = get_user_file_path(ROCKBOX_DIR, NEED_WRITE, name, sizeof(name)); 116 const char *_name = get_user_file_path(ROCKBOX_DIR, NEED_WRITE, name, sizeof(name));
118 snprintf(temp_filename, sizeof(temp_filename), 117 snprintf(temp_filename, sizeof(temp_filename),
119 "%slibtemp_binary_%d.dll", _name, i); 118 "%s/libtemp_binary_%d.dll", _name, i);
120#endif 119#endif
121 fd = open(temp_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0766); 120 fd = open(temp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0700);
122 if (fd >= 0) 121 if (fd >= 0)
123 break; /* Created a file ok */ 122 break; /* Created a file ok */
124 } 123 }
125 124
126 DEBUGF("Creating %s\n", temp_filename);
127 if (fd < 0) 125 if (fd < 0)
128 { 126 {
129 DEBUGF("open failed\n"); 127 DEBUGF("open failed\n");
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 9862b4a7a2..6547421668 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -179,9 +179,10 @@ struct mydir {
179 179
180typedef struct mydir MYDIR; 180typedef struct mydir MYDIR;
181 181
182#if 1 /* maybe this needs disabling for MSVC... */
183static unsigned int rockbox2sim(int opt) 182static unsigned int rockbox2sim(int opt)
184{ 183{
184#if 0
185/* this shouldn't be needed since we use the host's versions */
185 int newopt = O_BINARY; 186 int newopt = O_BINARY;
186 187
187 if(opt & 1) 188 if(opt & 1)
@@ -196,8 +197,10 @@ static unsigned int rockbox2sim(int opt)
196 newopt |= O_TRUNC; 197 newopt |= O_TRUNC;
197 198
198 return newopt; 199 return newopt;
199} 200#else
201 return opt|O_BINARY;
200#endif 202#endif
203}
201 204
202/** Simulator I/O engine routines **/ 205/** Simulator I/O engine routines **/
203#define IO_YIELD_THRESHOLD 512 206#define IO_YIELD_THRESHOLD 512
@@ -537,7 +540,7 @@ int sim_fsync(int fd)
537void *lc_open(const char *filename, char *buf, size_t buf_size) 540void *lc_open(const char *filename, char *buf, size_t buf_size)
538{ 541{
539 const char *sim_path = get_sim_pathname(filename); 542 const char *sim_path = get_sim_pathname(filename);
540 void *handle = _lc_open((const char*)UTF8_TO_OS(sim_path), buf, buf_size); 543 void *handle = _lc_open(UTF8_TO_OS(sim_path), buf, buf_size);
541 544
542 if (handle == NULL) 545 if (handle == NULL)
543 { 546 {