Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIN32 VS Unix merge cleanups

Tried to keep functionalities from both worlds, will for sure break some GUIs
  • Loading branch information...
commit 348d2851b3390ba44a8ddb02d84e023e883be332 1 parent 6017a07
@kwiirk authored
View
4 Makefile
@@ -4,8 +4,8 @@ DEFINES = -DLARGE_FILES -D_FILE_OFFSET_BITS=64
LIBS = -lcrypto
CC = gcc
-CFLAGS = -Wall -W -O3 -Ilibwbfs -I.
-#CFLAGS = -Wall -m32 -W -ggdb -Ilibwbfs -I.
+#CFLAGS = -Wall -W -O3 -Ilibwbfs -I.
+CFLAGS = -Wall -m32 -W -ggdb -Ilibwbfs -I.
LDFLAGS = -m32
VPATH+=libwbfs
View
23 disc_usage_table.c
@@ -114,39 +114,24 @@ static void copy_file(u64 offset, u64 size)
}
-static u32 do_fst(u8 *fst, const char *names, u32 i, char *indent, int is_last)
+static u32 do_fst(u8 *fst, const char *names, u32 i, char *indent)
{
u64 offset;
u32 size;
-#ifdef UNUSED_STUFF
- const char *name;
- u32 parent;
-#endif
u32 j;
-#ifdef UNUSED_STUFF
- name = names + (be32(fst + 12*i) & 0x00ffffff);
-#endif
size = be32(fst + 12*i + 8);
if (i == 0) {
for (j = 1; j < size; )
- j = do_fst(fst, names, j, indent, (j == size - 1));
+ j = do_fst(fst, names, j, indent);
return size;
}
-#ifdef UNUSED_STUFF
- if (fst[12*i]) {
- parent = be32(fst + 12*i + 4);
- is_last = (be32(fst + 12*parent + 8) == size);
- }
-#endif
-
-
if (fst[12*i]) {
for (j = i + 1; j < size; )
- j = do_fst(fst, names, j, indent, (j == size - 1));
+ j = do_fst(fst, names, j, indent);
indent[strlen(indent) - 4] = 0;
return size;
@@ -191,7 +176,7 @@ static void do_files(void)
indent[0] = 0;
if (n_files > 1)
- do_fst(fst, (char *)fst + 12*n_files, 0, indent, 0);
+ do_fst(fst, (char *)fst + 12*n_files, 0, indent);
free(fst);
}
View
6 libwbfs/libwbfs.c
@@ -799,8 +799,10 @@ u32 wbfs_extract_disc(wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector,v
if (spinner)
spinner(cur,tot);
- p->read_hdsector(p->callback_data, p->part_lba + iwlba*src_wbs_nlb, src_wbs_nlb, copy_buffer);
- write_dst_wii_sector(callback_data, i*dst_wbs_nlb, dst_wbs_nlb, copy_buffer);
+ if(p->read_hdsector(p->callback_data, p->part_lba + iwlba*src_wbs_nlb, src_wbs_nlb, copy_buffer))
+ ERROR("reading disc");
+ if(write_dst_wii_sector(callback_data, i*dst_wbs_nlb, dst_wbs_nlb, copy_buffer))
+ ERROR("writing disc");
}
else
{
View
18 libwbfs/libwbfs.h
@@ -223,10 +223,8 @@ u32 wbfs_add_disc(wbfs_t*p,read_wiidisc_callback_t read_src_wii_disc,
#endif
);
-#ifdef WIN32
u32 wbfs_estimate_disc(wbfs_t*p,read_wiidisc_callback_t read_src_wii_disc, void *callback_data,
partition_selector_t sel);
-#endif
/*! remove a wiidvd inside a partition */
u32 wbfs_rm_disc(wbfs_t*p, u8* discid);
@@ -255,6 +253,22 @@ u32 wbfs_extract_file(wbfs_disc_t*d, char *path);
// remove some sanity checks
void wbfs_set_force_mode(int force);
+
+/* OS specific functions provided by libwbfs_<os>.c */
+
+wbfs_t *wbfs_try_open(char *disk, char *partition, int reset);
+wbfs_t *wbfs_try_open_partition(char *fn, int reset);
+
+void *wbfs_open_file_for_read(char*filename);
+void *wbfs_open_file_for_write(char*filename);
+int wbfs_read_file(void*handle, int len, void *buf);
+void wbfs_close_file(void *handle);
+void wbfs_file_reserve_space(void*handle,long long size);
+void wbfs_file_truncate(void *handle,long long size);
+int wbfs_read_wii_file(void *_handle, u32 _offset, u32 count, void *buf);
+int wbfs_write_wii_sector_file(void *_handle, u32 lba, u32 count, void *buf);
+
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
View
68 libwbfs/libwbfs_unix.c
@@ -15,6 +15,74 @@
#include "libwbfs.h"
+void *wbfs_open_file_for_read(char*filename)
+{
+ FILE*f = fopen(filename,"r");
+ if (!f)
+ wbfs_fatal("unable to open file\n");
+ return (void*)f;
+}
+void *wbfs_open_file_for_write(char*filename)
+{
+ FILE*f = fopen(filename,"w");
+ if (!f)
+ wbfs_fatal("unable to open file\n");
+ return (void*)f;
+}
+int wbfs_read_file(void*handle, int len, void *buf)
+{
+ return fread(buf,len,1,(FILE*)handle);
+}
+void wbfs_close_file(void *handle)
+{
+ fclose((FILE*)handle);
+}
+void wbfs_file_reserve_space(void*handle, long long size)
+{
+ FILE*f=(FILE*)handle;
+ fseeko(f, size-1ULL, SEEK_SET);
+ fwrite("", 1, 1, f);
+}
+void wbfs_file_truncate(void *handle,long long size)
+{
+ ftruncate(fileno((FILE*)handle),size);
+}
+int wbfs_read_wii_file(void*_fp,u32 offset,u32 count,void*iobuf)
+{
+ FILE*fp =_fp;
+ u64 off = offset;
+ off<<=2;
+
+ if (fseeko(fp, off, SEEK_SET))
+ {
+ wbfs_error("error seeking in disc file (%ld)",off);
+ return 1;
+ }
+ if (fread(iobuf, count, 1, fp) != 1){
+ wbfs_error("error reading disc");
+ return 1;
+ }
+ return 0;
+}
+
+int wbfs_write_wii_sector_file(void*_fp,u32 lba,u32 count,void*iobuf)
+{
+ FILE*fp=_fp;
+ u64 off = lba;
+ off *=0x8000;
+
+ if (fseeko(fp, off, SEEK_SET))
+ {
+ wbfs_error("error seeking in disc file (%lld)",off);
+ return 1;
+ }
+ if (fwrite(iobuf, count*0x8000, 1, fp) != 1){
+ wbfs_error("error writing disc file");
+ return 1;
+ }
+ return 0;
+}
+
static int wbfs_fread_sector(void *_fp,u32 lba,u32 count,void*buf)
{
FILE*fp =_fp;
View
103 libwbfs/libwbfs_win32.c
@@ -10,6 +10,109 @@
#include "libwbfs.h"
+void *wbfs_open_file_for_read(char*filename)
+{
+ HANDLE *handle = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+
+ if (handle == INVALID_HANDLE_VALUE)
+ {
+ fprintf(stderr, "unable to open disc file\n");
+ return 0;
+ }
+ return (void*)handle;
+}
+void *wbfs_open_file_for_write(char*filename)
+{
+ HANDLE *handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
+ if (handle == INVALID_HANDLE_VALUE)
+ {
+ fprintf(stderr, "unable to open file\n");
+ return 0;
+ }
+ return (void*)handle;
+}
+int wbfs_read_file(void*handle, int len, void *buf)
+{
+ DWORD read;
+ ReadFile((HANDLE)handle, buf, len, &read, NULL);
+ return read;
+}
+void wbfs_close_file(void *handle)
+{
+ CloseHandle((HANDLE)handle);
+}
+void wbfs_file_reserve_space(void*handle,long long size)
+{
+ LARGE_INTEGER large;
+ large.QuadPart = size;
+ SetFilePointerEx((HANDLE)handle, large, NULL, FILE_BEGIN);
+ SetEndOfFile((HANDLE)handle);
+}
+int wbfs_read_wii_file(void *_handle, u32 _offset, u32 count, void *buf)
+{
+ HANDLE *handle = (HANDLE *)_handle;
+ LARGE_INTEGER large;
+ DWORD read;
+ u64 offset = _offset;
+
+ offset <<= 2;
+ large.QuadPart = offset;
+
+ if (SetFilePointerEx(handle, large, NULL, FILE_BEGIN) == FALSE)
+ {
+ wbfs_error("error seeking in disc file");
+ return 1;
+ }
+
+ read = 0;
+ if ((ReadFile(handle, buf, count, &read, NULL) == FALSE) || !read)
+ {
+ wbfs_error("error reading wii disc sector");
+ return 1;
+ }
+
+ if (read < count)
+ {
+ wbfs_warning("warning: requested %d, but read only %d bytes (trimmed or bad padded ISO)", count, read);
+ wbfs_memset((u8*)buf+read, 0, count-read);
+ }
+
+ return 0;
+}
+
+int wbfs_write_wii_sector_file(void *_handle, u32 lba, u32 count, void *buf)
+{
+ HANDLE *handle = (HANDLE *)_handle;
+ LARGE_INTEGER large;
+ DWORD written;
+ u64 offset = lba;
+
+ offset *= 0x8000;
+ large.QuadPart = offset;
+
+ if (SetFilePointerEx(handle, large, NULL, FILE_BEGIN) == FALSE)
+ {
+ fprintf(stderr,"\n\n%lld %p\n", offset, handle);
+ wbfs_error("error seeking in wii disc sector (write)");
+ return 1;
+ }
+
+ written = 0;
+ if (WriteFile(handle, buf, count * 0x8000, &written, NULL) == FALSE)
+ {
+ wbfs_error("error writing wii disc sector");
+ return 1;
+ }
+
+ if (written != count * 0x8000)
+ {
+ wbfs_error("error writing wii disc sector (size mismatch)");
+ return 1;
+ }
+
+ return 0;
+}
+
static int read_sector(void *_handle, u32 lba, u32 count, void *buf)
{
HANDLE *handle = (HANDLE *)_handle;
View
5 libwbfs_os.h
@@ -17,8 +17,9 @@
#define wbfs_error fatal
#define wbfs_warning non_fatal
#else
-#define wbfs_fatal(x) fatal(x)
-#define wbfs_error(x) non_fatal(x)
+#define wbfs_fatal fatal
+#define wbfs_error non_fatal
+#define wbfs_warning non_fatal
#endif
#include <stdlib.h>
View
9 tools.c
@@ -394,12 +394,13 @@ void fatal(const char *s, ...)
void non_fatal(const char *s, ...)
{
+ char message[256];
va_list ap;
va_start(ap, s);
- vfprintf(stderr, s, ap);
- fprintf(stderr, "\n");
- va_end(ap);
+ vsnprintf(message, sizeof message, s, ap);
+
+ perror(message);
}
//
@@ -499,7 +500,6 @@ void spinner(u64 x, u64 max)
fflush(stderr);
}
-#ifdef WIN32
void progress(u64 x, u64 max)
{
static time_t start_time;
@@ -560,4 +560,3 @@ void progress(u64 x, u64 max)
fprintf(stderr, "\rETA: %d:%02d:%02d [%s]", h, m, s, prg);
fflush(stderr);
}
-#endif
View
2  tools.h
@@ -61,8 +61,6 @@ void print_bytes(u8 *x, u32 n);
void hexdump(u8 *x, u32 n);
void dump_tmd(u8 *tmd);
void spinner(u64 x, u64 max);
-#ifdef WIN32
void progress(u64 x, u64 max);
-#endif
#endif
View
895 wbfs.c
@@ -2,14 +2,11 @@
// Licensed under the terms of the GNU GPL, version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
-#ifdef WIN32
-#include <windows.h>
-#endif
-
#include <stdio.h> /* for printf */
#include <stdlib.h> /* for exit */
#ifdef WIN32
+#include <windows.h>
#include "win32/xgetopt.h"
#include <direct.h>
#include <io.h>
@@ -19,172 +16,73 @@
#include <unistd.h>
#endif
#include <errno.h>
+#include <ctype.h>
#include <sys/stat.h>
#include "tools.h"
#include "libwbfs.h"
+/* remove unused warnings */
+#ifdef UNUSED
+#elif defined(__GNUC__)
+# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
+#elif defined(WIN32)
+#pragma warning(disable : 4786)
+# define UNUSED(x) x
+#else
+# define UNUSED(x) x
+#endif
-wbfs_t *wbfs_try_open(char *disk, char *partition, int reset);
-wbfs_t *wbfs_try_open_partition(char *fn, int reset);
-
#define GB (1024 * 1024 * 1024.)
#define MB (1024 * 1024)
-#ifdef WIN32
-
-int read_wii_disc_sector(void *_handle, u32 _offset, u32 count, void *buf)
-{
- HANDLE *handle = (HANDLE *)_handle;
- LARGE_INTEGER large;
- DWORD read;
- u64 offset = _offset;
-
- offset <<= 2;
- large.QuadPart = offset;
-
- if (SetFilePointerEx(handle, large, NULL, FILE_BEGIN) == FALSE)
- {
- wbfs_error("error seeking in disc file");
- return 1;
- }
-
- read = 0;
- if ((ReadFile(handle, buf, count, &read, NULL) == FALSE) || !read)
- {
- wbfs_error("error reading wii disc sector");
- return 1;
- }
-
- if (read < count)
- {
- wbfs_warning("warning: requested %d, but read only %d bytes (trimmed or bad padded ISO)", count, read);
- wbfs_memset((u8*)buf+read, 0, count-read);
- }
+int verbose;
- return 0;
-}
-int write_wii_disc_sector(void *_handle, u32 lba, u32 count, void *buf)
-{
- HANDLE *handle = (HANDLE *)_handle;
- LARGE_INTEGER large;
- DWORD written;
- u64 offset = lba;
-
- offset *= 0x8000;
- large.QuadPart = offset;
-
- if (SetFilePointerEx(handle, large, NULL, FILE_BEGIN) == FALSE)
- {
- fprintf(stderr,"\n\n%lld %p\n", offset, handle);
- wbfs_error("error seeking in wii disc sector (write)");
- return 1;
- }
-
- written = 0;
- if (WriteFile(handle, buf, count * 0x8000, &written, NULL) == FALSE)
- {
- wbfs_error("error writing wii disc sector");
- return 1;
- }
-
- if (written != count * 0x8000)
- {
- wbfs_error("error writing wii disc sector (size mismatch)");
- return 1;
- }
-
- return 0;
-}
-
-#else
-
-int read_wii_file(void*_fp,u32 offset,u32 count,void*iobuf)
-{
- FILE*fp =_fp;
- u64 off = offset;
- off<<=2;
-
- if (fseeko(fp, off, SEEK_SET))
- {
- wbfs_error("error seeking in disc file");
- return 1;
- }
- if (fread(iobuf, count, 1, fp) != 1){
- wbfs_error("error reading disc");
- return 1;
- }
- return 0;
-}
+/* helpers */
+static void _spinner(int x, int y){ spinner(x, y); }
+static void _progress(int x, int y){ progress(x, y); }
-int write_wii_sector_file(void*_fp,u32 lba,u32 count,void*iobuf)
+static int _wbfs_disc_read(void *fp, u32 lba, u32 count, void *iobuf)
{
- FILE*fp=_fp;
- u64 off = lba;
- off *=0x8000;
-
- if (fseeko(fp, off, SEEK_SET))
+ int ret = wbfs_disc_read(fp, lba, iobuf, count);
+ static int num_fail=0;
+ if (ret)
{
- fprintf(stderr,"\n\n%lld %p\n",off,_fp);
- wbfs_error("error seeking in written disc file");
- return 1;
- }
- if (fwrite(iobuf, count*0x8000, 1, fp) != 1){
- wbfs_error("error writing disc file");
- return 1;
+ if(num_fail==0)
+ wbfs_error("error reading lba probably the two wbfs don't have the same granularity. Ignoring...\n");
+ if(num_fail++ > 0x100)
+ {
+ wbfs_fatal( "too many error giving up...\n");
+ return 1;
+ }
}
- return 0;
+ else
+ num_fail = 0;
+ return 0;
}
-#endif
+/* Applets */
-#ifdef WIN32
-void wbfs_applet_list(wbfs_t *p, BOOL shortcmd)
-#else
-int wbfs_applet_ls(wbfs_t *p)
-#endif
+void wbfs_applet_ls(wbfs_t *p, int UNUSED(argc), char** UNUSED(argv))
{
int count = wbfs_count_discs(p);
- if (count == 0)
- {
- fprintf(stderr,"wbfs is empty\n");
- }
- else
- {
- int i;
- u32 size;
- u8 *b = wbfs_ioalloc(0x100);
- for (i = 0; i < count; i++)
- {
- if (!wbfs_get_disc_info(p, i, b, 0x100, &size))
- {
-#ifdef WIN32
- if(shortcmd)
- {
- fprintf(stderr, "%c%c%c%c%c%c %s\n", b[0], b[1], b[2], b[3], b[4], b[5], b + 0x20);
- }
- else
- {
- fprintf(stderr, "%c%c%c%c%c%c %4dM %s\n", b[0], b[1], b[2], b[3], b[4], b[5], (u32)(size * 4ULL / (MB)), b + 0x20);
- }
-#else
- fprintf(stderr, "%c%c%c%c%c%c|@|%-55s|@|%.2fG\n",b[0], b[1], b[2], b[3], b[4], b[5],
- b + 0x20,size*4ULL/(GB));
-#endif
- }
- }
+ int i;
+ u32 size;
+ u8 *b = wbfs_ioalloc(0x100);
+ for (i = 0; i < count; i++)
+ {
+ if (!wbfs_get_disc_info(p, i, b, 0x100, &size))
+ fprintf(stderr, "%c%c%c%c%c%c|@|%-55s|@|%.2fG\n",b[0], b[1], b[2], b[3], b[4], b[5],
+ b + 0x20,size*4ULL/(GB));
+ }
- wbfs_iofree(b);
- }
+ wbfs_iofree(b);
-#ifdef WIN32
- if(!shortcmd)
-#endif
-#ifndef __APPLE__
+ if(verbose)
{
u32 blcount = wbfs_count_usedblocks(p);
fprintf(stderr, "------------\n %u Files - Total: %.2fG, Used: %.2fG, Free: %.2fG\n",
@@ -193,248 +91,117 @@ int wbfs_applet_ls(wbfs_t *p)
(float)(p->n_wbfs_sec-blcount) * p->wbfs_sec_sz / GB,
(float)(blcount) * p->wbfs_sec_sz / GB);
}
-#endif
-#ifndef WIN32
- return 0;
-#endif
}
-#ifdef WIN32
-void wbfs_applet_info(wbfs_t *p, BOOL shortcmd)
-#else
-int wbfs_applet_df(wbfs_t *p)
-#endif
+void wbfs_applet_df(wbfs_t *p, int UNUSED(argc), char** UNUSED(argv))
{
u32 count = wbfs_count_usedblocks(p);
-#ifdef WIN32
fprintf(stderr, "wbfs\n");
fprintf(stderr, " blocks : %u\n", count);
fprintf(stderr, " total : %.2fG\n", (float)p->n_wbfs_sec * p->wbfs_sec_sz / GB);
fprintf(stderr, " used : %.2fG\n", (float)(p->n_wbfs_sec-count) * p->wbfs_sec_sz / GB);
fprintf(stderr, " free : %.2fG\n", (float)(count) * p->wbfs_sec_sz / GB);
-
-#else
-#ifdef MAC_UI_STUFF
- fprintf(stderr, "Total: %.2fG Used: %.2fG Free: %.2fG\n",
- (float)p->n_wbfs_sec*p->wbfs_sec_sz/GB,
- (float)(p->n_wbfs_sec-count)*p->wbfs_sec_sz/GB,
- (float)(count)*p->wbfs_sec_sz/GB);
-#else
- fprintf(stderr, "%.2f|@|%.2f\n",
- (float)p->n_wbfs_sec*p->wbfs_sec_sz/GB,
- (float)(count)*p->wbfs_sec_sz/GB);
-#endif
-
-#endif
- return p != 0;
}
-#ifdef WIN32
-void wbfs_applet_makehbc(wbfs_t *p, BOOL shortcmd)
-#else
-int wbfs_applet_mkhbc(wbfs_t *p)
-#endif
+void wbfs_applet_mkhbc(wbfs_t *p, int UNUSED(argc), char** UNUSED(argv))
{
int count = wbfs_count_discs(p);
-#ifndef WIN32
- char filename[7];
-#endif
FILE *xml;
- if (count == 0)
- {
- fprintf(stderr,"wbfs is empty\n");
- }
- else
- {
- int i;
- u32 size;
- u8 *b = wbfs_ioalloc(0x100);
+ int i;
+ u32 size;
+ u8 *b = wbfs_ioalloc(0x100);
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++)
+ {
#ifdef WIN32
- char dirname[7 + 1];
- char dolname[7 + 1 + 8 + 1];
- char pngname[7 + 1 + 8 + 1];
- char xmlname[7 + 1 + 8 + 1];
+ char dirname[7 + 1];
+ char dolname[7 + 1 + 8 + 1];
+ char pngname[7 + 1 + 8 + 1];
+ char xmlname[7 + 1 + 8 + 1];
- wbfs_get_disc_info(p, i, b, 0x100, &size);
+ wbfs_get_disc_info(p, i, b, 0x100, &size);
- snprintf(dirname, 7, "%c%c%c%c%c%c", b[0], b[1], b[2], b[3], b[4], b[5]);
- snprintf(dolname, 7 + 1 + 8, "%c%c%c%c%c%c\\boot.dol", b[0], b[1], b[2], b[3], b[4], b[5]);
- snprintf(pngname, 7 + 1 + 8, "%c%c%c%c%c%c\\icon.png", b[0], b[1], b[2], b[3], b[4], b[5]);
- snprintf(xmlname, 7 + 1 + 8, "%c%c%c%c%c%c\\meta.xml", b[0], b[1], b[2], b[3], b[4], b[5]);
+ snprintf(dirname, 7, "%c%c%c%c%c%c", b[0], b[1], b[2], b[3], b[4], b[5]);
+ snprintf(dolname, 7 + 1 + 8, "%c%c%c%c%c%c\\boot.dol", b[0], b[1], b[2], b[3], b[4], b[5]);
+ snprintf(pngname, 7 + 1 + 8, "%c%c%c%c%c%c\\icon.png", b[0], b[1], b[2], b[3], b[4], b[5]);
+ snprintf(xmlname, 7 + 1 + 8, "%c%c%c%c%c%c\\meta.xml", b[0], b[1], b[2], b[3], b[4], b[5]);
- CreateDirectory(dirname, NULL);
- printf("%s\n", dirname);
+ CreateDirectory(dirname, NULL);
+ printf("%s\n", dirname);
- CopyFile("boot.dol", dolname, FALSE);
- CopyFile("icon.png", pngname, FALSE);
+ CopyFile("boot.dol", dolname, FALSE);
+ CopyFile("icon.png", pngname, FALSE);
- xml = fopen(xmlname, "wb");
+ xml = fopen(xmlname, "wb");
#else
- wbfs_get_disc_info(p,i,b,0x100,&size);
- snprintf(filename,7,"%c%c%c%c%c%c",b[0], b[1], b[2], b[3], b[4], b[5]);
- mkdir(filename, 0777);
- printf("%s\n",filename);
- if (chdir(filename))
- wbfs_fatal("chdir");
-#ifndef MAC_UI_STUFF
- system("cp ../boot.dol .");
- system("cp ../icon.png .");
-#endif
-
- xml = fopen("meta.xml","w");
-
-#endif
-
- fprintf(xml,"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
- fprintf(xml,"<app>\n\t<name>%s</name>\n", b + 0x20);
- fprintf(xml,"<short_description>%.2fGB on USB HD</short_description>\n", size * 4ULL / GB);
-#ifdef WIN32
- fprintf(xml,"<long_description>This launches the yal wbfs game loader by Kwiirk for discid %s</long_description>\n", dirname);
-
-#else
-#ifdef MAC_UI_STUFF
- fprintf(xml,"<long_description>Click the Load Button to play %s from your USB Drive</long_description>\n", b+0x20);
-#else
- fprintf(xml,"<long_description>This launches the yal wbfs game loader by Kwiirk for discid %s</long_description>\n",filename);
-#endif
-
-#endif
- fprintf(xml,"</app>");
- fclose(xml);
-
-#ifndef WIN32
- if (chdir(".."))
- wbfs_fatal("chdir");
-#endif
- }
-
- wbfs_iofree(b);
- }
-
-#ifndef WIN32
- return p!=0;
-#endif
-
+ char filename[7];
+ wbfs_get_disc_info(p,i,b,0x100,&size);
+ snprintf(filename,7,"%c%c%c%c%c%c",b[0], b[1], b[2], b[3], b[4], b[5]);
+ mkdir(filename, 0777);
+ printf("%s\n",filename);
+ if (chdir(filename))
+ wbfs_fatal("chdir");
+ system("cp ../boot.dol .");
+ system("cp ../icon.png .");
+
+ xml = fopen("meta.xml","w");
+ if (chdir(".."))
+ wbfs_fatal("chdir");
+
+#endif
+ fprintf(xml,"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
+ fprintf(xml,"<app>\n\t<name>%s</name>\n", b + 0x20);
+ fprintf(xml,"<short_description>%.2fGB on USB HD</short_description>\n", size * 4ULL / GB);
+ fprintf(xml,"<long_description>Click the Load Button to play %s from your USB Drive</long_description>\n", b+0x20);
+ fprintf(xml,"</app>");
+ fclose(xml);
+ }
+ wbfs_iofree(b);
}
-#ifdef WIN32
-void wbfs_applet_init(wbfs_t *p, BOOL shortcmd)
-#else
-int wbfs_applet_init(wbfs_t *p)
-#endif
+void wbfs_applet_init(wbfs_t *UNUSED(p),int UNUSED(argc),char** UNUSED(argv))
{
// nothing to do actually..
// job already done by the reset flag of the wbfs_open_partition
-#ifdef WIN32
- fprintf(stderr, "wbfs initialized.\n");
-#else
- return p != 0;
-#endif
}
-
-#ifdef WIN32
-void wbfs_applet_estimate(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
+void wbfs_applet_estimate(wbfs_t *p, int UNUSED(argc), char **argv)
{
- HANDLE *handle = CreateFile(argv[0], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
-
- if (handle == INVALID_HANDLE_VALUE)
- {
- fprintf(stderr, "unable to open disc file\n");
- }
- else
- {
- u32 estimation = wbfs_estimate_disc(p, read_wii_disc_sector, handle, ONLY_GAME_PARTITION);
- fprintf(stderr, "%.2fG\n", estimation / (GB));
- }
-}
-#endif
-int _wbfs_disc_read(void *fp, u32 lba, u32 count, void *iobuf)
-{
- int ret = wbfs_disc_read(fp, lba, iobuf, count);
- static int num_fail=0;
- if (ret)
+ void *handle = wbfs_open_file_for_read(argv[0]);
+ if(handle)
{
- if(num_fail==0)
- wbfs_error("error reading lba probably the two wbfs don't have the same granularity. Ignoring...\n");
- if(num_fail++ > 0x100)
- {
- wbfs_fatal( "too many error giving up...\n");
- return 1;
- }
+ u32 estimation = wbfs_estimate_disc(p, wbfs_read_wii_file, handle, ONLY_GAME_PARTITION);
+ fprintf(stderr, "%.2fG\n", estimation / (GB));
}
- else
- num_fail = 0;
- return 0;
}
-static void _spinner(int x, int y){ spinner(x, y); }
-#ifdef WIN32
-static void _progress(int x, int y){ progress(x, y); }
-#endif
-#ifdef WIN32
-void wbfs_applet_add(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
-#else
-int wbfs_applet_add(wbfs_t *p,char*argv)
-#endif
+void wbfs_applet_add(wbfs_t *p, int UNUSED(argc), char**argv)
{
-#ifndef WIN32
- FILE *f = fopen(argv,"r");
-#endif
+ void *handle = wbfs_open_file_for_read(argv[0]);
u8 discinfo[7];
wbfs_disc_t *d;
-
-#ifdef WIN32
- HANDLE *handle = CreateFile(argv[0], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
-
- if (handle == INVALID_HANDLE_VALUE)
- {
- fprintf(stderr, "unable to open disc file\n");
- }
- else
- {
- DWORD read = 0;
- ReadFile(handle, discinfo, 6, &read, NULL);
-
- d = wbfs_open_disc(p, discinfo);
-
- if (d)
- {
- discinfo[6] = 0;
- fprintf(stderr, "%s already in disc...\n", discinfo);
- wbfs_close_disc(d);
- }
- else
- {
- wbfs_add_disc(p, read_wii_disc_sector, handle, shortcmd ? _progress : _spinner, ONLY_GAME_PARTITION, 0, (argc>1) ? argv[1] : NULL);
- }
-
- CloseHandle(handle);
- }
-
-#else
- if(!f)
+ if(!handle)
wbfs_fatal("unable to open disc file");
else
{
- fread(discinfo,6,1,f);
+ wbfs_read_file(handle,6,discinfo);
if (memcmp(discinfo, "WBFS", 4) == 0) // add all games in the wbfs partition
{
- fclose(f);
- wbfs_t *src_p = wbfs_try_open_partition(argv, 0);
+ wbfs_t *src_p;
+ int i, count;
+ u8 *b;
+ wbfs_close_file(handle);
+ src_p = wbfs_try_open_partition(argv[0], 0);
if (!src_p)
{
wbfs_fatal("incorrect wbfs file");
- return 1;
+ return ;
}
- int i, count = wbfs_count_discs(src_p);
- u8 *b = wbfs_ioalloc(0x100);
+ count = wbfs_count_discs(src_p);
+ b = wbfs_ioalloc(0x100);
if (count==0)
wbfs_fatal("no disc in wbfs");
for (i=0;i<count;i++)
@@ -443,7 +210,7 @@ int wbfs_applet_add(wbfs_t *p,char*argv)
d = wbfs_open_disc(p, b);
if(!d){ // not here already.
d = wbfs_open_disc(src_p, b);
- wbfs_add_disc(p, _wbfs_disc_read, d, _spinner, ONLY_GAME_PARTITION, 0);
+ wbfs_add_disc(p, _wbfs_disc_read, d, verbose?_spinner:_progress, ONLY_GAME_PARTITION, 0);
}
wbfs_close_disc(d);
}
@@ -458,45 +225,28 @@ int wbfs_applet_add(wbfs_t *p,char*argv)
discinfo[6]=0;
fprintf(stderr,"%s already in disc..\n",discinfo);
wbfs_close_disc(d);
- return 0;
+ return ;
} else
- return wbfs_add_disc(p,read_wii_file,f,_spinner,ONLY_GAME_PARTITION,0);
+ wbfs_add_disc(p,wbfs_read_wii_file,handle,verbose?_spinner:_progress,ONLY_GAME_PARTITION,0);
}
}
- return 1;
-#endif
-
}
-#ifdef WIN32
-void wbfs_applet_remove(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
+void wbfs_applet_rm(wbfs_t *p, int UNUSED(argc), char **argv)
{
if ( wbfs_rm_disc(p, (u8 *)(argv[0])) )
- {
wbfs_error("Couldn't find %s", argv[0]);
- }
- else
- {
- printf("Done.\n");
- }
}
-#else
-int wbfs_applet_rm(wbfs_t *p,char *argv)
-{
- return wbfs_rm_disc(p,(u8*)argv);
-}
-#endif
-#ifdef WIN32
-void wbfs_applet_extract(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
+void wbfs_applet_extract(wbfs_t *p, int argc, char **argv)
{
wbfs_disc_t *d;
d = wbfs_open_disc(p, (u8 *)(argv[0]));
if (d)
{
- HANDLE *handle;
+ void *handle;
char isoname[0x100];
int i,len;
@@ -524,25 +274,17 @@ void wbfs_applet_extract(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
strncpy(isoname + len, ".iso", 0x100 - len);
- handle = CreateFile(isoname, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
-
- if (handle == INVALID_HANDLE_VALUE)
- {
- fprintf(stderr, "unable to open disc file (%s) for writing\n", isoname);
- }
- else
- {
- LARGE_INTEGER large;
-
- fprintf(stderr, "writing to %s\n", isoname);
+ handle = wbfs_open_file_for_write(isoname);
- large.QuadPart = (d->p->n_wii_sec_per_disc / 2) * 0x8000ULL;
- SetFilePointerEx(handle, large, NULL, FILE_BEGIN);
- SetEndOfFile(handle);
+ if (handle)
+ {
+ // write a zero at the end of the iso to ensure the correct size
+ // XXX should check if the game is DVD9..
+ wbfs_file_reserve_space(handle, (d->p->n_wii_sec_per_disc/2)* 0x8000ULL);
- wbfs_extract_disc(d,write_wii_disc_sector, handle, _spinner);
-
- CloseHandle(handle);
+ wbfs_extract_disc(d,wbfs_write_wii_sector_file, handle, _spinner);
+
+ wbfs_close_file(handle);
}
wbfs_close_disc(d);
@@ -552,337 +294,114 @@ void wbfs_applet_extract(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
wbfs_error("Couldn't find %s", argv[0]);
}
}
-
-#else
-int wbfs_applet_extract(wbfs_t *p, char *argv)
+void wbfs_applet_ren(wbfs_t *p, int UNUSED(argc), char **argv)
{
- wbfs_disc_t *d;
- int ret = 1;
- d = wbfs_open_disc(p,(u8*)argv);
- if (d)
- {
- char buf[0x100];
- int i, len;
- /* get the name of the title to find out the name of the iso */
- strncpy(buf,(char*)d->header->disc_header_copy+0x20,0x100);
- len = strlen(buf);
- // replace silly chars by '_'
- for( i = 0; i < len; i++)
- if(buf[i]==' ' || buf[i]=='/' || buf[i]==':')
- buf[i] = '_';
- strncpy(buf+len,".iso",0x100-len);
- FILE *f=fopen(buf,"w");
- if (!f) {
- wbfs_fatal("unable to open dest file");
- }
- else {
- fprintf(stderr,"writing to %s\n",buf);
-
- // write a zero at the end of the iso to ensure the correct size
- // XXX should check if the game is DVD9..
- fseeko(f,(d->p->n_wii_sec_per_disc/2)*0x8000ULL-1ULL,SEEK_SET);
- fwrite("",1,1,f);
-
- ret = wbfs_extract_disc(d,write_wii_sector_file,f,_spinner);
-
- fclose(f);
- }
-
- wbfs_close_disc(d);
-
- }
- else {
- fprintf(stderr, "%s not in disc in disc..\n", argv);
- }
- return ret;
-}
-
-#endif
-
-
-#ifdef WIN32
-void wbfs_applet_rename(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
-{
- if(argc<2)
+ if(wbfs_ren_disc(p, (u8*)argv[0], (u8*)argv[1]))
{
- _set_errno(EINVAL);
wbfs_error("error");
}
-
- if(wbfs_ren_disc(p, argv[0], argv[1]))
- {
- wbfs_error("error");
- }
-
- printf("Done.\n");
}
-
-#else
-
-int wbfs_applet_rename(wbfs_t *p,char *arg1, char *arg2)
-{
- if(wbfs_ren_disc(p,(u8*)arg1,(u8*)arg2))
+void wbfs_applet_nid(wbfs_t *p, int UNUSED(argc), char **argv)
+{
+ if(wbfs_nid_disc(p,(u8*)argv[0], (u8*)argv[1]))
{
wbfs_error("error");
}
-
- return 0;
}
-int wbfs_applet_create(char*argv)
+
+void wbfs_applet_create(char**argv)
{
char buf[1024];
- strncpy(buf,argv,1019);
+ strncpy(buf,argv[0],1019);
strcpy(buf+strlen(buf),".wbfs");
- FILE *f=fopen(buf,"w");
- if(!f)
+ void *handle= wbfs_open_file_for_write(buf);
+ if(!handle)
wbfs_fatal("unable to open dest file");
else{
// reserve space for the maximum size.
- fseeko(f,143432*2*0x8000ULL-1ULL,SEEK_SET);
- fwrite("",1,1,f);
- fclose(f);
+ wbfs_file_reserve_space(handle, 143432*2*0x8000ULL);
+ wbfs_close_file(handle);
wbfs_t *p = wbfs_try_open_partition(buf,1);
if(p){
- wbfs_applet_add(p,argv);
+ wbfs_applet_add(p,1,argv);
wbfs_trim(p);
- ftruncate(fileno(p->callback_data),p->n_hd_sec*512ULL);
+ wbfs_file_truncate(p->callback_data,p->n_hd_sec*512ULL);
wbfs_close(p);
}
}
- return 0;
-}
-
-#endif
-
-int wbfs_applet_nid(wbfs_t *p,char *arg1, char *arg2)
-{
- if(wbfs_nid_disc(p,(u8*)arg1, (u8*)arg2))
- {
- wbfs_error("error");
- }
-
- return 0;
}
-
-#ifdef WIN32
struct wbfs_applets
{
char *command;
- char *shortcmd;
- char *arglist;
- void (*function_with_argument)(wbfs_t *p, BOOL shortcmd, int argc, char *argv[]);
- void (*function)(wbfs_t *p, BOOL shortcmd);
+ char *alternatecmd;
+ char *help;
+ int needed_argc;
+ void (*function)(wbfs_t *p, int argc, char**argv);
}
-#else
-struct wbfs_applets
-{
- char *opt;
- int (*function_with_argument)(wbfs_t *p, char *argv);
- int (*function)(wbfs_t *p);
- int (*func_args)(wbfs_t *p, char *arg1, char *arg2);
-}
-
-#endif
+#define APPLET(x, y, n, z) { #x, #y, z, n,wbfs_applet_##x }
-#ifdef WIN32
-#define APPLET(x, y, z) { #x, #y, #z, wbfs_applet_##x, NULL }
-#define APPLET_NOARG(x, y) { #x, #y, "", NULL, wbfs_applet_##x }
-
-#else
-#define APPLET(x) { #x,wbfs_applet_##x,NULL,NULL}
-#define APPLET_NOARG(x) { #x,NULL,wbfs_applet_##x,NULL}
-#define APPLET_ARGS(x) { #x, NULL, NULL, wbfs_applet_##x}
-#endif
-
-
-#ifdef WIN32
-wbfs_applets[] =
-{
- APPLET_NOARG(list, l),
- APPLET_NOARG(info, i),
- APPLET_NOARG(makehbc, hbc),
- APPLET_NOARG(init, init),
- APPLET(estimate, e, <file>),
- APPLET(add, a, <file> [new_name]),
- APPLET(rename, r, <ID> <new_name>),
- APPLET(extract, x, <ID> [iso_name]),
- APPLET(remove, d, <ID>)
-};
-
-#undef APPLET
-#undef APPLET_NOARG
-
-
-#else
wbfs_applets[] =
{
- APPLET_NOARG(ls),
- APPLET_NOARG(df),
- APPLET_NOARG(mkhbc),
- APPLET_NOARG(init),
- APPLET(add),
- APPLET(rm),
- APPLET_ARGS(rename),
- APPLET_ARGS(nid),
- APPLET(extract),
+ APPLET(ls,list,0," \n\t\t\t\t list all games in wbfs"),
+ APPLET(df,info,0," \n\t\t\t\t show disc usage statistics"),
+ APPLET(mkhbc,makehbc,0," \n\t\t\t\t make homebrew channel compatible directories"),
+ APPLET(init,init,0," \n\t\t\t\t init a wbfs partition"),
+ APPLET(add,add,1,"file.iso|file.wbfs \n\t\t\t\t add game(s) to wbfs"),
+ APPLET(rm,remove,1,"gameid \n\t\t\t\t remove game from wbfs"),
+ APPLET(ren,rename,2,"gameid newname \n\t\t\t\t change name of a wbfs game"),
+ APPLET(nid,changeid,2,"gameid newgameid \n\t\t\t\t Change id of a wbfs game"),
+ APPLET(extract,extract,1,"gameid \n\t\t\t\t extract a game iso from wbfs"),
};
-#endif
-
static int num_applets = sizeof(wbfs_applets) / sizeof(wbfs_applets[0]);
-#ifdef WIN32
void usage(char **argv)
{
int i;
+#ifdef WIN32
fprintf(stderr, "\nwbfs windows port build 'delta'. Mod v1.0 by Sorg.\n\nUsage:\n");
-
- for (i = 0; i < num_applets; i++)
- {
- if(!strcmp(wbfs_applets[i].command, wbfs_applets[i].shortcmd))
- {
- fprintf(stderr, " %s <drive letter> %s %s\n", argv[0], wbfs_applets[i].command, wbfs_applets[i].arglist);
- }
- else
- {
- fprintf(stderr, " %s <drive letter> %s|%s %s\n", argv[0], wbfs_applets[i].command, wbfs_applets[i].shortcmd, wbfs_applets[i].arglist);
- }
- }
-}
-
+ fprintf(stderr, "%s [-f] [-v] <drive letter> command args \n",argv[0]);
#else
-void usage(char **argv)
-{
- int i;
fprintf(stderr,
- "Usage: %s [-d disk|-p partition]\n",
+ "\nUsage: %s [-d disk|-p partition] [-v] [-f] commands args\n",
argv[0]);
-
- for (i = 0; i < num_applets; i++)
- fprintf(stderr, "\t %s %s %s\n",wbfs_applets[i].opt,wbfs_applets[i].function_with_argument||wbfs_applets[i].func_args
- ?"(file|id)":"",
- wbfs_applets[i].func_args?"(newid|newname)":"");
- exit(EXIT_FAILURE);
-}
+
#endif
-
-#ifdef WIN32
-int main(int argc, char *argv[])
-{
- int opt;
- int i;
- BOOL executed = FALSE;
- char *partition = NULL;
- char *command = NULL;
+ fprintf(stderr, " [-f] force mode\n [-v] verbose mode\n");
+ fprintf(stderr, "create game.iso \n\t\t\t\t Create a wbfs compressed version of the iso\n");
- while ((opt = getopt(argc, argv, "d:hf")) != -1)
- {
- switch (opt)
- {
- case 'f':
- wbfs_set_force_mode(1);
- break;
-
- case 'h':
- default: /* '?' */
- return usage(argv);
- }
- }
-
- if (optind + 2 > argc)
- {
- return usage(argv);
- }
-
- partition = argv[optind + 0];
- command = argv[optind + 1];
-
- if (partition == NULL || strlen(partition) != 1)
- {
- fprintf(stderr, "You must supply a valid drive letter.\n");
- return EXIT_FAILURE;
- }
-
- if (strcmp(command, "init") == 0)
- {
- char c;
- fprintf(stderr, "!!! Warning ALL data on drive '%s' will be lost irretrievably !!!\n\n", partition);
- fprintf(stderr, "Are you sure? (y/n): ");
-
- c = getchar();
- if (toupper(c) != 'Y')
- {
- fprintf(stderr, "Aborted.\n");
- return EXIT_FAILURE;
- }
-
- fprintf(stderr, "\n");
- }
-
for (i = 0; i < num_applets; i++)
{
- struct wbfs_applets *ap = &wbfs_applets[i];
-
- if(_stricmp(command, ap->command) == 0 || _stricmp(command, ap->shortcmd) == 0)
- {
- wbfs_t *p;
-
- p = wbfs_try_open(NULL, partition, ap->function == wbfs_applet_init);
- if (!p)
- {
- executed = TRUE;
- break;
- }
-
- if (ap->function_with_argument)
- {
- if (optind + 3 > argc)
- {
- break;
- }
- else
- {
- executed = TRUE;
- ap->function_with_argument(p, _stricmp(command, ap->shortcmd) == 0, argc-(optind+2), argv+(optind + 2));
- }
- }
- else
- {
- executed = TRUE;
- ap->function(p, _stricmp(command, ap->shortcmd) == 0);
- }
-
- wbfs_close(p);
- break;
- }
- }
-
- if (executed == FALSE)
- {
- return usage(argv);
+ if(!strcmp(wbfs_applets[i].command, wbfs_applets[i].alternatecmd))
+ fprintf(stderr, "%s %s\n", wbfs_applets[i].command, wbfs_applets[i].help);
+ else
+ fprintf(stderr, "%s|%s %s\n", wbfs_applets[i].command, wbfs_applets[i].alternatecmd, wbfs_applets[i].help);
}
-
- return EXIT_SUCCESS;
}
-#else
int main(int argc, char *argv[])
{
int opt;
int i;
char *partition = NULL, *disk = NULL;
-
- while ((opt = getopt(argc, argv, "p:d:hf")) != -1) {
+ char *command;
+#ifdef WIN32
+ while ((opt = getopt(argc, argv, "hfv")) != -1) {
+#else
+ while ((opt = getopt(argc, argv, "p:d:hfv")) != -1) {
+#endif
switch (opt) {
+#ifndef WIN32
case 'p':
partition = optarg;
break;
case 'd':
disk = optarg;
break;
+#endif
case 'f':
wbfs_set_force_mode(1);
break;
@@ -896,13 +415,44 @@ int main(int argc, char *argv[])
usage(argv);
exit(EXIT_FAILURE);
}
-
- if ( strcmp(argv[optind], "create") == 0 )
+#ifdef WIN32
+ partition = argv[optind++];
+ if (optind >= argc) {
+ usage(argv);
+ exit(EXIT_FAILURE);
+ }
+ if (strlen(partition) != 1)
+ {
+ fprintf(stderr, "You must supply a valid drive letter.\n");
+ return EXIT_FAILURE;
+ }
+#endif
+ command = argv[optind++];
+ // special case for the create command :-/
+ if ( strcmp(command, "create") == 0 )
{
if (optind+1 >= argc)
usage(argv);
- else
- return wbfs_applet_create(argv[optind+1]);
+ else{
+ wbfs_applet_create(argv+optind);
+ return 0;
+ }
+ }
+
+ if (strcmp(command, "init") == 0)
+ {
+ char c;
+ fprintf(stderr, "!!! Warning ALL data on drive '%s' will be lost irretrievably !!!\n\n", partition);
+ fprintf(stderr, "Are you sure? (y/n): ");
+
+ c = getchar();
+ if (toupper(c) != 'Y')
+ {
+ fprintf(stderr, "Aborted.\n");
+ return EXIT_FAILURE;
+ }
+
+ fprintf(stderr, "\n");
}
int command_found = 0;
@@ -910,38 +460,26 @@ int main(int argc, char *argv[])
for (i = 0; i < num_applets; i++)
{
struct wbfs_applets *ap = &wbfs_applets[i];
- if ( strcmp( argv[optind], ap->opt) == 0 )
+ if ( strcmp( command, ap->command) == 0 || strcmp( command, ap->alternatecmd) == 0)
{
command_found = 1;
wbfs_t *p = wbfs_try_open(disk, partition,
- ap->function== wbfs_applet_init);
+ ap->function== wbfs_applet_init);
if(!p)
break;
- if (ap->function_with_argument)
- {
- if (optind + 1 >= argc)
- usage(argv);
- else
- while (optind + 1 < argc){
- ap->function_with_argument(p, argv[optind+1]);
- optind++;
- }
- }
- else if (ap->func_args){
- if (optind + 2 >= argc)
- usage(argv);
- else
- while (optind + 2 < argc){
- ap->func_args(p, argv[optind+1], argv[optind+2]);
- optind+=2;
- }
- }
- else
+
+ if (optind + ap->needed_argc > argc)
{
- ap->function(p);
+ fprintf(stderr,"too few arguments for command: %s\n", command);
+ usage(argv);
}
-
- wbfs_close(p);
+ else
+ do {
+ ap->function(p, ap->needed_argc, argv + optind );
+ optind += ap->needed_argc;
+ }
+ while (ap->needed_argc && optind + ap->needed_argc <= argc);
+ wbfs_close(p);
break;
}
}
@@ -950,9 +488,8 @@ int main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
else {
- printf("Unknown command: %s\n", argv[optind]);
+ fprintf(stderr,"Unknown command: %s\n", command);
+ usage(argv);
exit(EXIT_FAILURE);
}
}
-
-#endif
Please sign in to comment.
Something went wrong with that request. Please try again.