diff options
| author | [email protected] <[email protected]> | 2012-09-08 03:37:46 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-09-08 03:37:46 +0000 |
| commit | e39022f3c75ce44f3c80b302c0df14e241cb001a (patch) | |
| tree | 5fc2f47f9c3ee143b1fc0ce489774235e3baadc9 /components | |
| parent | c6c2a504f61be8df84dfdbfc39fb78c2e0a8a45b (diff) | |
dfs: add format flag O_BINARY
lzo: change to use posix interface.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2283 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components')
| -rw-r--r-- | components/dfs/include/dfs_def.h | 1 | ||||
| -rw-r--r-- | components/dfs/include/dfs_posix.h | 1 | ||||
| -rw-r--r-- | components/external/lzo/lzo.c | 55 |
3 files changed, 34 insertions, 23 deletions
diff --git a/components/dfs/include/dfs_def.h b/components/dfs/include/dfs_def.h index b96118fe41..c0fe47fe0c 100644 --- a/components/dfs/include/dfs_def.h +++ b/components/dfs/include/dfs_def.h @@ -183,6 +183,7 @@ #define DFS_O_EXCL 0x0000200 #define DFS_O_TRUNC 0x0001000 #define DFS_O_APPEND 0x0002000 +#define DFS_O_BINARY 0x0008000 #define DFS_O_DIRECTORY 0x0200000 /* File flags */ diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index 93cd9747a4..9627a4fe73 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -29,6 +29,7 @@ #define O_EXCL DFS_O_EXCL #define O_TRUNC DFS_O_TRUNC #define O_APPEND DFS_O_APPEND +#define O_BINARY DFS_O_BINARY #define O_DIRECTORY DFS_O_DIRECTORY #define S_IFMT DFS_S_IFMT diff --git a/components/external/lzo/lzo.c b/components/external/lzo/lzo.c index 6d0c6ec00d..0df4ab3834 100644 --- a/components/external/lzo/lzo.c +++ b/components/external/lzo/lzo.c @@ -10,13 +10,22 @@ */
#include <rtthread.h>
#include "minilzo.h"
-#include <rtgui/rtgui_config.h>
-#include <rtgui/filerw.h>
+
#ifdef RT_USING_FINSH
#include <finsh.h>
#endif
#define RT_USING_LZO
-#if defined(RT_USING_LZO) && defined(RTGUI_USING_DFS_FILERW)
+#if defined(RT_USING_LZO) && defined(RT_USING_DFS)
+
+#ifdef _WIN32
+#pragma warning(disable: 4996)
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <io.h>
+#else
+#include <dfs_posix.h>
+#endif
/* the worst of allocation */
#define LZO1X_WORST(x) ( (x) + ((x)/16) + 64 + 3 )
@@ -47,7 +56,7 @@ char* parse_lzo_error_code(int error_code) int lzo(char *srcfile, char *destfile)
{
int result;
- struct rtgui_filerw *file;
+ int fd;
struct stat s;
lzo_bytep in;
lzo_bytep out;
@@ -62,14 +71,14 @@ int lzo(char *srcfile, char *destfile) out = rt_malloc(LZO1X_WORST(in_len));
if (out == RT_NULL) return -1;
- file = rtgui_filerw_create_file(srcfile, "rb");
- if(file == RT_NULL)
+ fd = open(srcfile, O_RDONLY, 0);
+ if(fd < 0)
{
result = -1;
goto _exit;
}
- rtgui_filerw_read(file, in, in_len, 1);
- rtgui_filerw_close(file);
+ read(fd, in, in_len);
+ close(fd);
result = lzo1x_1_compress(in, in_len, out, &out_len, wrkmem);
if(result != LZO_E_OK)
@@ -79,16 +88,16 @@ int lzo(char *srcfile, char *destfile) goto _exit;
}
- file = rtgui_filerw_create_file(destfile, "wb");
- if(file == RT_NULL)
+ fd = open(destfile, O_WRONLY | O_BINARY | O_CREAT, 0);
+ if(fd < 0)
{
result = -1;
goto _exit;
}
- rtgui_filerw_write(file, &in_len, sizeof(lzo_uint), 1); /* source file len */
- rtgui_filerw_write(file, out, out_len, 1);
- rtgui_filerw_close(file);
+ write(fd, &in_len, sizeof(lzo_uint)); /* source file len */
+ write(fd, out, out_len);
+ close(fd);
rt_kprintf("compress lzo ok!\n");
result = 0;
@@ -104,7 +113,7 @@ FINSH_FUNCTION_EXPORT(lzo, compress a file. usage:lzo(src, dest)); int lzode(char *srcfile, char *destfile)
{
int result;
- struct rtgui_filerw *file;
+ int fd;
struct stat s;
lzo_bytep in=RT_NULL;
lzo_bytep out=RT_NULL;
@@ -114,18 +123,18 @@ int lzode(char *srcfile, char *destfile) stat(srcfile, &s);
in_len = s.st_size;
- file = rtgui_filerw_create_file(srcfile, "rb");
- if(file == RT_NULL) return 0;
+ fd = open(srcfile, O_RDONLY, 0);
+ if(fd < 0) return 0;
- rtgui_filerw_read(file, &out_len, sizeof(lzo_uint), 1); /* source file len */
+ read(fd, &out_len, sizeof(lzo_uint)); /* source file len */
in_len -= sizeof(lzo_uint);
in = rt_malloc(in_len);
if (in == RT_NULL) return -1;
out = rt_malloc(out_len);
if (out == RT_NULL) return -1;
- rtgui_filerw_read(file, in, in_len, 1);
- rtgui_filerw_close(file);
+ read(fd, in, in_len);
+ close(fd);
result = lzo1x_decompress(in, in_len, out, &out_len, RT_NULL);
if(result != LZO_E_OK)
@@ -135,14 +144,14 @@ int lzode(char *srcfile, char *destfile) goto _exit;
}
- file = rtgui_filerw_create_file(destfile, "wb");
- if(file == RT_NULL)
+ fd = open(destfile, O_WRONLY | O_BINARY | O_CREAT, 0);
+ if(fd < 0)
{
result = -1;
goto _exit;
}
- rtgui_filerw_write(file, out, out_len, 1);
- rtgui_filerw_close(file);
+ write(fd, out, out_len);
+ close(fd);
rt_kprintf("decompress lzo ok!\n");
result = 0;
|
