OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [argz/] [buf_findstr.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* Copyright (C) 2002 by  Red Hat, Incorporated. All rights reserved.
2
 *
3
 * Permission to use, copy, modify, and distribute this software
4
 * is freely granted, provided that this notice is preserved.
5
 */
6
 
7
#include <errno.h>
8
#include <sys/types.h>
9
#include <string.h>
10
#include <stdlib.h>
11
 
12
#include "buf_findstr.h"
13
 
14
/* Find string str in buffer buf of length buf_len.  Point buf to character after string,
15
   or set it to NULL if end of buffer is reached.  Return 1 if found, 0 if not. */
16
int
17
_buf_findstr(const char *str, char **buf, size_t *buf_len)
18
{
19
  int i = 0;
20
  int j = 0;
21
 
22
  for (i = 0; i < *buf_len; i++)
23
    {
24
      if (str[0] == (*buf)[i])
25
        {
26
          j = i;
27
          while (str[j - i] && (str[j - i] == (*buf)[j])) j++;
28
          if(str[j - i] == '\0')
29
            {
30
              *buf += j;
31
              *buf_len -= j;
32
              return 1;
33
            }
34
        }
35
    }
36
 
37
  if (i == *buf_len)
38
    {
39
      *buf += *buf_len;
40
      *buf_len = 0;
41
    }
42
 
43
  return 0;
44
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.