Blame src/strscpy.c

Packit Service e2ebee
/* Copyright libuv project contributors. All rights reserved.
Packit Service e2ebee
 *
Packit Service e2ebee
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit Service e2ebee
 * of this software and associated documentation files (the "Software"), to
Packit Service e2ebee
 * deal in the Software without restriction, including without limitation the
Packit Service e2ebee
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit Service e2ebee
 * sell copies of the Software, and to permit persons to whom the Software is
Packit Service e2ebee
 * furnished to do so, subject to the following conditions:
Packit Service e2ebee
 *
Packit Service e2ebee
 * The above copyright notice and this permission notice shall be included in
Packit Service e2ebee
 * all copies or substantial portions of the Software.
Packit Service e2ebee
 *
Packit Service e2ebee
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service e2ebee
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service e2ebee
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit Service e2ebee
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service e2ebee
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit Service e2ebee
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit Service e2ebee
 * IN THE SOFTWARE.
Packit Service e2ebee
 */
Packit Service e2ebee
Packit Service 7c31a4
#include "strscpy.h"
Packit Service 7c31a4
#include <limits.h>  /* SSIZE_MAX */
Packit Service 7c31a4
Packit Service 7c31a4
ssize_t uv__strscpy(char* d, const char* s, size_t n) {
Packit Service 7c31a4
  size_t i;
Packit Service 7c31a4
Packit Service 7c31a4
  for (i = 0; i < n; i++)
Packit Service 7c31a4
    if ('\0' == (d[i] = s[i]))
Packit Service 7c31a4
      return i > SSIZE_MAX ? UV_E2BIG : (ssize_t) i;
Packit Service 7c31a4
Packit Service 7c31a4
  if (i == 0)
Packit Service 7c31a4
    return 0;
Packit Service 7c31a4
Packit Service 7c31a4
  d[--i] = '\0';
Packit Service 7c31a4
Packit Service 7c31a4
  return UV_E2BIG;
Packit Service 7c31a4
}