From a41dbfe25ad6eebb1a5bc976fc2ed7f8591f07d2 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 13 Apr 2013 08:01:05 -0700 Subject: [PATCH] AROS: Add an example for using the SYNC API to AROS While the ASYNC API is probably always preferable, the SYNC API is easier to use. The SYNC API is probably what most users want. --- aros/Makefile.AROS | 4 ++- aros/aros_compat.c | 2 +- examples/nfsclient-sync.c | 74 +++++++-------------------------------- 3 files changed, 17 insertions(+), 63 deletions(-) diff --git a/aros/Makefile.AROS b/aros/Makefile.AROS index 54f7249..9ad038c 100755 --- a/aros/Makefile.AROS +++ b/aros/Makefile.AROS @@ -10,7 +10,7 @@ OBJS+=portmap/portmap.o portmap/libnfs-raw-portmap.o OBJS+=rquota/rquota.o rquota/libnfs-raw-rquota.o OBJS+=aros/aros_compat.o -EXAMPLES=examples/nfsclient-listservers +EXAMPLES=examples/nfsclient-listservers examples/nfsclient-sync all: lib/libnfs.a $(EXAMPLES) @@ -22,6 +22,8 @@ lib/libnfs.a: $(OBJS) $(CC) $(CFLAGS) -c -o $@ $< examples/nfsclient-listservers: examples/nfsclient-listservers.c lib/libnfs.a + $(CC) $(CFLAGS) -o $@ $< lib/libnfs.a +examples/nfsclient-sync: examples/nfsclient-sync.c lib/libnfs.a $(CC) $(CFLAGS) -o $@ $< lib/libnfs.a diff --git a/aros/aros_compat.c b/aros/aros_compat.c index 9a6cd3b..6419956 100644 --- a/aros/aros_compat.c +++ b/aros/aros_compat.c @@ -81,7 +81,7 @@ int aros_inet_pton(int af, char *src, void *dst) struct sockaddr_in sin; sin.sin_addr.s_addr = inet_addr(src); - memcpy(dst, &sin.sin_addr.s_addr, sizeof(sin.sin_addr,s_addr)); + memcpy(dst, &sin.sin_addr.s_addr, sizeof(sin.sin_addr.s_addr)); return 1; } diff --git a/examples/nfsclient-sync.c b/examples/nfsclient-sync.c index e42214a..4bd2c0b 100644 --- a/examples/nfsclient-sync.c +++ b/examples/nfsclient-sync.c @@ -22,22 +22,22 @@ */ #ifdef WIN32 #include "win32_compat.h" +#pragma comment(lib, "ws2_32.lib") +WSADATA wsaData; #else #include #include #include +#include +#ifndef AROS #include #endif - - -#if defined(WIN32) -#pragma comment(lib, "ws2_32.lib") -WSADATA wsaData; -#else -#include -#include #endif +#ifdef AROS +#include "aros_compat.h" +#endif + #include #include #include @@ -47,8 +47,6 @@ WSADATA wsaData; #include #include "libnfs-zdr.h" #include "libnfs.h" -#include /* for authunix_create() */ -#include #include "libnfs-raw.h" #include "libnfs-raw-mount.h" @@ -67,22 +65,6 @@ void print_usage(void) fprintf(stderr, "Usage: nfsclient-sync [-?|--help] [--usage] \n"); } -void print_help(void) -{ - fprintf(stderr, "Usage: nfsclient-sync [OPTION...] \n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Help options:\n"); - fprintf(stderr, " -?, --help Show this help message\n"); - fprintf(stderr, " --usage Display brief usage message\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "NFS URL format : nfs:///\n"); - fprintf(stderr, "\n"); - fprintf(stderr, " is either of:\n"); - fprintf(stderr, " \"hostname\" nfs.example\n"); - fprintf(stderr, " \"ipv4-address\" 10.1.1.27\n"); - fprintf(stderr, " \"ipv6-address\" [fce0::1]\n"); -} - int main(int argc, char *argv[]) { struct nfs_context *nfs = NULL; @@ -95,51 +77,21 @@ int main(int argc, char *argv[]) struct nfsdirent *nfsdirent; struct statvfs svfs; exports export, tmp; - int show_help = 0, show_usage = 0; - poptContext pc; - const char **extra_argv; - int extra_argc = 0; const char *url = NULL; char *server = NULL, *path = NULL, *strp; - struct poptOption popt_options[] = { - { "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL }, - { "usage", 0, POPT_ARG_NONE, &show_usage, 0, "Display brief usage message", NULL }, - POPT_TABLEEND - }; - -#if defined(WIN32) +#ifdef WIN32 if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) { printf("Failed to start Winsock2\n"); exit(10); } #endif - pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_POSIXMEHARDER); - if ((res = poptGetNextOpt(pc)) < -1) { - fprintf(stderr, "Failed to parse option : %s %s\n", - poptBadOption(pc, 0), poptStrerror(res)); - exit(10); - } - extra_argv = poptGetArgs(pc); - if (extra_argv) { - url = *extra_argv; - extra_argv++; - while (extra_argv[extra_argc]) { - extra_argc++; - } - } - poptFreeContext(pc); - - if (show_help != 0) { - print_help(); - exit(0); - } +#ifdef AROS + aros_init_socket(); +#endif - if (show_usage != 0) { - print_usage(); - exit(0); - } + url = argv[1]; if (url == NULL) { fprintf(stderr, "No URL specified.\n"); -- 2.34.1