Bug 479382 - libmar doesn't build on windows ce (uses posix file io); r=benjamin

This commit is contained in:
Brad Lassey 2009-03-15 14:59:59 +01:00
Родитель e487bbc8e6
Коммит 934bb1d83e
2 изменённых файлов: 41 добавлений и 1 удалений

Просмотреть файл

@ -128,7 +128,14 @@ static int mar_concat_file(FILE *fp, const char *path) {
int mar_create(const char *dest, int num_files, char **files) {
struct MarItemStack stack;
PRUint32 offset_to_index = 0, size_of_index;
#ifdef WINCE
WIN32_FIND_DATAW file_data;
PRUnichar wide_path[MAX_PATH];
size_t size;
PRInt32 flags;
#else
struct stat st;
#endif
FILE *fp;
int i, rv = -1;
@ -148,12 +155,24 @@ int mar_create(const char *dest, int num_files, char **files) {
stack.last_offset = MAR_ID_SIZE + sizeof(PRUint32);
for (i = 0; i < num_files; ++i) {
#ifdef WINCE
MultiByteToWideChar(CP_ACP, 0, files[i], -1, wide_path, MAX_PATH);
if (!FindFirstFile(wide_path, &file_data)) {
#else
if (stat(files[i], &st)) {
#endif
fprintf(stderr, "ERROR: file not found: %s\n", files[i]);
goto failure;
}
#ifdef WINCE
flags = (file_data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ?
0444 : 0666;
size = (file_data.nFileSizeHigh * (MAXDWORD + 1)) + file_data.nFileSizeLow;
if (mar_push(&stack, size, flags, files[i]))
#else
if (mar_push(&stack, st.st_size, st.st_mode & 0777, files[i]))
#endif
goto failure;
/* concatenate input file to archive */
@ -181,6 +200,13 @@ failure:
free(stack.head);
fclose(fp);
if (rv)
#ifdef WINCE
{
MultiByteToWideChar(CP_ACP, 0, dest, -1, wide_path, MAX_PATH);
DeleteFileW(wide_path);
}
#else
remove(dest);
#endif
return rv;
}

Просмотреть файл

@ -48,18 +48,29 @@
#ifdef XP_WIN
#include <io.h>
#include <direct.h>
#ifdef WINCE
#include <windows.h>
#endif
#endif
/* Ensure that the directory containing this file exists */
static int mar_ensure_parent_dir(const char *path)
{
char *slash = strrchr(path, '/');
#ifdef WINCE
wchar_t wide_path[MAX_PATH];
#endif
if (slash)
{
*slash = '\0';
mar_ensure_parent_dir(path);
#ifdef XP_WIN
#ifdef WINCE
MultiByteToWideChar(CP_ACP, 0, path, -1, wide_path, MAX_PATH);
CreateDirectory(wide_path, NULL);
#else
_mkdir(path);
#endif
#else
mkdir(path, 0755);
#endif
@ -75,7 +86,9 @@ static int mar_test_callback(MarFile *mar, const MarItem *item, void *unused) {
if (mar_ensure_parent_dir(item->name))
return -1;
#ifdef WINCE
fp = fopen(item->name, "bw");
#else
#ifdef XP_WIN
fd = _open(item->name, _O_BINARY|_O_CREAT|_O_TRUNC|_O_WRONLY, item->flags);
#else
@ -85,6 +98,7 @@ static int mar_test_callback(MarFile *mar, const MarItem *item, void *unused) {
return -1;
fp = fdopen(fd, "wb");
#endif
if (!fp)
return -1;