]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
slirp: add slirp own version of pstrcpy
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 17 Jan 2019 11:43:47 +0000 (15:43 +0400)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Thu, 7 Feb 2019 13:49:08 +0000 (15:49 +0200)
Remove a dependency on qemu util.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
slirp/slirp.c
slirp/tftp.c
slirp/util.c
slirp/util.h

index 9ec1e4c62f373da3342a451d6a733c471e4758e6..b5c4788489df4f7023f82cc22c3ededd8e2729ac 100644 (file)
@@ -320,8 +320,8 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
     slirp->vprefix_len = vprefix_len;
     slirp->vhost_addr6 = vhost6;
     if (vhostname) {
-        pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
-                vhostname);
+        slirp_pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
+                      vhostname);
     }
     slirp->tftp_prefix = g_strdup(tftp_path);
     slirp->bootp_filename = g_strdup(bootfile);
index 6fb381ef3375f9f0b3ce2cd91781e47756087353..f0bcc72c925868beaa7b7c54912468219fe38f86 100644 (file)
@@ -216,7 +216,7 @@ static void tftp_send_error(struct tftp_session *spt,
 
   tp->tp_op = htons(TFTP_ERROR);
   tp->x.tp_error.tp_error_code = htons(errorcode);
-  pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), msg);
+  slirp_pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), msg);
 
   m->m_len = sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX + 2) + 3 + strlen(msg)
              - sizeof(struct udphdr);
index 59f6713c8b1dbcd24c99f783e78df15cf1575da6..84f5afdbc3afe3168b85cf461aea849a1608534e 100644 (file)
@@ -188,3 +188,20 @@ int slirp_closesocket(int fd)
     return ret;
 }
 #endif /* WIN32 */
+
+void slirp_pstrcpy(char *buf, int buf_size, const char *str)
+{
+    int c;
+    char *q = buf;
+
+    if (buf_size <= 0)
+        return;
+
+    for(;;) {
+        c = *str++;
+        if (c == 0 || q >= buf + buf_size - 1)
+            break;
+        *q++ = c;
+    }
+    *q = '\0';
+}
index 4f6e80c3edf33fa466a018ecbe540a21dc741bce..586517bb3059cab56f88f9dd890422659f255cc1 100644 (file)
@@ -91,4 +91,6 @@ static inline int slirp_socket_set_fast_reuse(int fd)
 #endif
 }
 
+void slirp_pstrcpy(char *buf, int buf_size, const char *str);
+
 #endif