nfs_lseek{,_async}: allow negative offsets and guard against file positions < 0
[deb_libnfs.git] / lib / init.c
index df3c2aa2bd90cc25a7302907428c362648f7b85e..36d4880006d9f244b804fdf0a8b2631c2a220924 100644 (file)
@@ -57,7 +57,9 @@ struct rpc_context *rpc_init_context(void)
        memset(rpc, 0, sizeof(struct rpc_context));
 
        rpc->magic = RPC_CONTEXT_MAGIC;
-       rpc->encodebuflen = 65536;
+
+       /* Allow 1M of data (for writes) and some */
+       rpc->encodebuflen = 1024 * 1024 + 4096;
        rpc->encodebuf = malloc(rpc->encodebuflen);
        if (rpc->encodebuf == NULL) {
                free(rpc);
@@ -74,7 +76,7 @@ struct rpc_context *rpc_init_context(void)
        salt += 0x01000000;
        rpc->fd = -1;
        rpc->tcp_syncnt = RPC_PARAM_UNDEFINED;
-#ifdef WIN32
+#if defined(WIN32) || defined(ANDROID)
        rpc->uid = 65534;
        rpc->gid = 65534;
 #else
@@ -130,16 +132,18 @@ void rpc_set_gid(struct rpc_context *rpc, int gid) {
 void rpc_set_error(struct rpc_context *rpc, char *error_string, ...)
 {
         va_list ap;
+       char *old_error_string = rpc->error_string;
 
        assert(rpc->magic == RPC_CONTEXT_MAGIC);
 
-       if (rpc->error_string != NULL) {
-               free(rpc->error_string);
-       }
         va_start(ap, error_string);
        rpc->error_string = malloc(1024);
        vsnprintf(rpc->error_string, 1024, error_string, ap);
         va_end(ap);
+
+       if (old_error_string != NULL) {
+               free(old_error_string);
+       }
 }
 
 char *rpc_get_error(struct rpc_context *rpc)