コード例 #1
0
ファイル: pr32919.c プロジェクト: ImmanuelHaffner/JACCo-old
void _IO_vfprintf_internal ( char *f )
{
  static const void *const step0_jumps[] = { &&do_form_unknown, &&do_flag_plus, &&do_form_float };
  const void * ptr = step0_jumps[0];
  do {
    char spec;
    spec = (*++f);
    goto *ptr;
do_flag_plus:
     read_int (&f);
do_number:
    _itoa_word (spec);
do_form_float:
    if (ptr != ((void *)0))
    {
      spec = 'x';
      goto do_number;
    }
    if (spec != 'S')
      __strnlen ();
    return;
    do_form_unknown:;
  }
  while (*f != '\0');
}
コード例 #2
0
ファイル: challenge_02.c プロジェクト: mabj/ctf_ucon2
char *strnlen (char *str) {
  int i;
  for (i = 0; i < strlen(str); i++) {
    str[i] = __strnlen((int) str[i]);
  }
  return str;
}
コード例 #3
0
/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
   except the last into the character SEP.  */
void
__argz_stringify (char *argz, size_t len, int sep)
{
  if (len > 0)
    while (1)
      {
	size_t part_len = __strnlen (argz, len);
	argz += part_len;
	len -= part_len;
	if (len-- <= 1)		/* includes final '\0' we want to stop at */
	  break;
	*argz++ = sep;
      }
}
コード例 #4
0
ファイル: strncat.c プロジェクト: AubrCool/glibc
char *
STRNCAT (char *s1, const char *s2, size_t n)
{
  char *s = s1;

  /* Find the end of S1.  */
  s1 += strlen (s1);

  size_t ss = __strnlen (s2, n);

  s1[ss] = '\0';
  memcpy (s1, s2, ss);

  return s;
}
コード例 #5
0
ファイル: getlogin_r.c プロジェクト: riscv/riscv-glibc
/* Return at most NAME_LEN characters of the login name of the user in NAME.
   If it cannot be determined or some other error occurred, return the error
   code.  Otherwise return 0.  */
int
__getlogin_r (char *name, size_t name_len)
{
  string_t login;
  error_t err;

  if (err = __USEPORT (PROC, __proc_getlogin (port, login)))
    return errno = err;

  size_t len = __strnlen (login, sizeof login - 1) + 1;
  if (len > name_len)
    {
      errno = ERANGE;
      return errno;
    }

  memcpy (name, login, len);
  return 0;
}
コード例 #6
0
ファイル: ptsname.c プロジェクト: gf-chen/glibc
/* Store at most BUFLEN characters of the pathname of the slave pseudo
   terminal associated with the master FD is open on in BUF.
   Return 0 on success, otherwise an error number.  */
int
__ptsname_r (int fd, char *buf, size_t buflen)
{
  string_t peername;
  size_t len;
  error_t err;

  if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername)))
    return __hurd_dfail (fd, err), errno;

  len = __strnlen (peername, sizeof peername - 1) + 1;
  if (len > buflen)
    {
      errno = ERANGE;
      return ERANGE;
    }

  memcpy (buf, peername, len);
  return 0;
}
コード例 #7
0
ファイル: fnmatch.c プロジェクト: siddhesh/glibc
int
fnmatch (const char *pattern, const char *string, int flags)
{
# if HANDLE_MULTIBYTE
  if (__builtin_expect (MB_CUR_MAX, 1) != 1)
    {
      mbstate_t ps;
      size_t n;
      const char *p;
      wchar_t *wpattern_malloc = NULL;
      wchar_t *wpattern;
      wchar_t *wstring_malloc = NULL;
      wchar_t *wstring;
      size_t alloca_used = 0;

      /* Convert the strings into wide characters.  */
      memset (&ps, '\0', sizeof (ps));
      p = pattern;
#ifdef _LIBC
      n = __strnlen (pattern, 1024);
#else
      n = strlen (pattern);
#endif
      if (__glibc_likely (n < 1024))
	{
	  wpattern = (wchar_t *) alloca_account ((n + 1) * sizeof (wchar_t),
						 alloca_used);
	  n = mbsrtowcs (wpattern, &p, n + 1, &ps);
	  if (__glibc_unlikely (n == (size_t) -1))
	    /* Something wrong.
	       XXX Do we have to set `errno' to something which mbsrtows hasn't
	       already done?  */
	    return -1;
	  if (p)
	    {
	      memset (&ps, '\0', sizeof (ps));
	      goto prepare_wpattern;
	    }
	}
      else
	{
	prepare_wpattern:
	  n = mbsrtowcs (NULL, &pattern, 0, &ps);
	  if (__glibc_unlikely (n == (size_t) -1))
	    /* Something wrong.
	       XXX Do we have to set `errno' to something which mbsrtows hasn't
	       already done?  */
	    return -1;
	  if (__glibc_unlikely (n >= (size_t) -1 / sizeof (wchar_t)))
	    {
	      __set_errno (ENOMEM);
	      return -2;
	    }
	  wpattern_malloc = wpattern
	    = (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
	  assert (mbsinit (&ps));
	  if (wpattern == NULL)
	    return -2;
	  (void) mbsrtowcs (wpattern, &pattern, n + 1, &ps);
	}

      assert (mbsinit (&ps));
#ifdef _LIBC
      n = __strnlen (string, 1024);
#else
      n = strlen (string);
#endif
      p = string;
      if (__glibc_likely (n < 1024))
	{
	  wstring = (wchar_t *) alloca_account ((n + 1) * sizeof (wchar_t),
						alloca_used);
	  n = mbsrtowcs (wstring, &p, n + 1, &ps);
	  if (__glibc_unlikely (n == (size_t) -1))
	    {
	      /* Something wrong.
		 XXX Do we have to set `errno' to something which
		 mbsrtows hasn't already done?  */
	    free_return:
	      free (wpattern_malloc);
	      return -1;
	    }
	  if (p)
	    {
	      memset (&ps, '\0', sizeof (ps));
	      goto prepare_wstring;
	    }
	}
      else
	{
	prepare_wstring:
	  n = mbsrtowcs (NULL, &string, 0, &ps);
	  if (__glibc_unlikely (n == (size_t) -1))
	    /* Something wrong.
	       XXX Do we have to set `errno' to something which mbsrtows hasn't
	       already done?  */
	    goto free_return;
	  if (__glibc_unlikely (n >= (size_t) -1 / sizeof (wchar_t)))
	    {
	      free (wpattern_malloc);
	      __set_errno (ENOMEM);
	      return -2;
	    }

	  wstring_malloc = wstring
	    = (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
	  if (wstring == NULL)
	    {
	      free (wpattern_malloc);
	      return -2;
	    }
	  assert (mbsinit (&ps));
	  (void) mbsrtowcs (wstring, &string, n + 1, &ps);
	}

      int res = internal_fnwmatch (wpattern, wstring, wstring + n,
				   flags & FNM_PERIOD, flags, NULL,
				   alloca_used);

      free (wstring_malloc);
      free (wpattern_malloc);

      return res;
    }
# endif  /* mbstate_t and mbsrtowcs or _LIBC.  */

  return internal_fnmatch (pattern, string, string + strlen (string),
			   flags & FNM_PERIOD, flags, NULL, 0);
}
コード例 #8
0
ファイル: mbsrtowcs_l.c プロジェクト: riscv/riscv-glibc
size_t
attribute_hidden
__mbsrtowcs_l (wchar_t *dst, const char **src, size_t len, mbstate_t *ps,
	       locale_t l)
{
  struct __gconv_step_data data;
  size_t result;
  int status;
  struct __gconv_step *towc;
  size_t non_reversible;
  const struct gconv_fcts *fcts;

  /* Tell where we want the result.  */
  data.__invocation_counter = 0;
  data.__internal_use = 1;
  data.__flags = __GCONV_IS_LAST;
  data.__statep = ps;

  /* Get the conversion functions.  */
  fcts = get_gconv_fcts (l->__locales[LC_CTYPE]);

  /* Get the structure with the function pointers.  */
  towc = fcts->towc;
  __gconv_fct fct = towc->__fct;
#ifdef PTR_DEMANGLE
  if (towc->__shlib_handle != NULL)
    PTR_DEMANGLE (fct);
#endif

  /* We have to handle DST == NULL special.  */
  if (dst == NULL)
    {
      mbstate_t temp_state;
      wchar_t buf[64];		/* Just an arbitrary size.  */
      const unsigned char *inbuf = (const unsigned char *) *src;
      const unsigned char *srcend = inbuf + strlen (*src) + 1;

      temp_state = *data.__statep;
      data.__statep = &temp_state;

      result = 0;
      data.__outbufend = (unsigned char *) buf + sizeof (buf);
      do
	{
	  data.__outbuf = (unsigned char *) buf;

	  status = DL_CALL_FCT (fct, (towc, &data, &inbuf, srcend, NULL,
				      &non_reversible, 0, 1));

	  result += (wchar_t *) data.__outbuf - buf;
	}
      while (status == __GCONV_FULL_OUTPUT);

      if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT)
	{
	  /* There better should be a NUL wide char at the end.  */
	  assert (((wchar_t *) data.__outbuf)[-1] == L'\0');
	  /* Don't count the NUL character in.  */
	  --result;
	}
    }
  else
    {
      /* This code is based on the safe assumption that all internal
	 multi-byte encodings use the NUL byte only to mark the end
	 of the string.  */
      const unsigned char *srcp = (const unsigned char *) *src;
      const unsigned char *srcend;

      data.__outbuf = (unsigned char *) dst;
      data.__outbufend = data.__outbuf + len * sizeof (wchar_t);

      status = __GCONV_FULL_OUTPUT;

      while (len > 0)
	{
	  /* Pessimistic guess as to how much input we can use.  In the
	     worst case we need one input byte for one output wchar_t.  */
	  srcend = srcp + __strnlen ((const char *) srcp, len) + 1;

	  status = DL_CALL_FCT (fct, (towc, &data, &srcp, srcend, NULL,
				      &non_reversible, 0, 1));
	  if ((status != __GCONV_EMPTY_INPUT
	       && status != __GCONV_INCOMPLETE_INPUT)
	      /* Not all input read.  */
	      || srcp != srcend
	      /* Reached the end of the input.  */
	      || srcend[-1] == '\0')
	    break;

	  len = (wchar_t *) data.__outbufend - (wchar_t *) data.__outbuf;
	}

      /* Make the end if the input known to the caller.  */
      *src = (const char *) srcp;

      result = (wchar_t *) data.__outbuf - dst;

      /* We have to determine whether the last character converted
	 is the NUL character.  */
      if ((status == __GCONV_OK || status == __GCONV_EMPTY_INPUT)
	  && ((wchar_t *) dst)[result - 1] == L'\0')
	{
	  assert (result > 0);
	  assert (__mbsinit (data.__statep));
	  *src = NULL;
	  --result;
	}
    }

  /* There must not be any problems with the conversion but illegal input
     characters.  */
  assert (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT
	  || status == __GCONV_ILLEGAL_INPUT
	  || status == __GCONV_INCOMPLETE_INPUT
	  || status == __GCONV_FULL_OUTPUT);

  if (status != __GCONV_OK && status != __GCONV_FULL_OUTPUT
      && status != __GCONV_EMPTY_INPUT && status != __GCONV_INCOMPLETE_INPUT)
    {
      result = (size_t) -1;
      __set_errno (EILSEQ);
    }

  return result;
}