summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-27 12:38:25 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-27 12:38:25 +0000
commit2c2e261648d5ae1befe5c4f269a655cc06b6e1e9 (patch)
tree16ea536a547deb252276c29d34eeee08f029866f /firmware
parent79798ff5f30dea7419f360e197763abb3b46259a (diff)
downloadrockbox-2c2e261648d5ae1befe5c4f269a655cc06b6e1e9.tar.gz
rockbox-2c2e261648d5ae1befe5c4f269a655cc06b6e1e9.zip
Use system headers a bit more: use host's fcntl.h for O_RDONLY etc.
Removes the need to fix up those in the simulator. Also work around some posix-mingw incompatibilities (e.g. getcwd()). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27904 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-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
4 files changed, 59 insertions, 26 deletions
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");