/*********************************************************
- * Copyright (C) 1998-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2017 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
char *Str_Strcpy(char *dst, // OUT:
const char *src, // IN:
size_t maxLen); // IN:
+char *Str_Strncpy(char *dest, // OUT:
+ size_t destSize, // IN:
+ const char *src, // IN:
+ size_t n); // IN:
char *Str_Strcat(char *dst, // IN/OUT:
const char *src, // IN:
size_t maxLen); // IN:
}
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Str_Strncpy --
+ *
+ * Unlike strncpy:
+ * * Guaranteed to NUL-terminate.
+ * * If the src string is shorter than n bytes, does NOT zero-fill the
+ * remaining bytes.
+ * * Panics if a buffer overrun would have occurred.
+ *
+ * Results:
+ * Same as strncpy.
+ *
+ * Side effects:
+ * None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+char *
+Str_Strncpy(char *dest, // IN/OUT
+ size_t destSize, // IN: Size of dest
+ const char *src, // IN: String to copy
+ size_t n) // IN: Max chars of src to copy, not including NUL
+{
+ ASSERT(dest != NULL);
+ ASSERT(src != NULL);
+
+ n = Str_Strlen(src, n);
+
+ if (n >= destSize) {
+ Panic("%s:%d Buffer too small\n", __FILE__, __LINE__);
+ }
+
+ memcpy(dest, src, n);
+ dest[n] = '\0';
+ return dest;
+}
+
+
/*
*----------------------------------------------------------------------
*
* Specifically, this function will Panic if a buffer overrun would
* have occurred.
*
- * Guaranteed to NUL-terminate if bufSize > 0.
+ * Guaranteed to NUL-terminate.
*
* Results:
* Same as strncat.
if (!(bufLen + n < bufSize ||
bufLen + strlen(src) < bufSize)) {
- Panic("%s:%d Buffer too small\n", __FILE__,__LINE__);
+ Panic("%s:%d Buffer too small\n", __FILE__, __LINE__);
}
/*
if (bufLen + n >= bufSize &&
bufLen + wcslen(src) >= bufSize) {
- Panic("%s:%d Buffer too small\n", __FILE__,__LINE__);
+ Panic("%s:%d Buffer too small\n", __FILE__, __LINE__);
}
/*