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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [sim/] [testsuite/] [sim/] [cris/] [c/] [readlink4.c] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 jlechner
/* Check for corner case: readlink of too-long name.
2
#notarget: cris*-*-elf
3
*/
4
 
5
#include <unistd.h>
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <errno.h>
10
#include <stdarg.h>
11
 
12
void bye (const char *s, int i)
13
{
14
  fprintf (stderr, "%s: %d\n", s, i);
15
  fflush (NULL);
16
  abort ();
17
}
18
 
19
int main (int argc, char *argv[])
20
{
21
  char *buf;
22
  char buf2[1024];
23
  int max, i;
24
 
25
  /* We assume this limit is what we see in the simulator as well.  */
26
#ifdef PATH_MAX
27
  max = PATH_MAX;
28
#else
29
  max = pathconf (argv[0], _PC_PATH_MAX);
30
#endif
31
 
32
  max *= 10;
33
 
34
  if (max <= 0)
35
    bye ("path_max", max);
36
 
37
  if ((buf = malloc (max + 1)) == NULL)
38
    bye ("malloc", 0);
39
 
40
  strcat (buf, argv[0]);
41
 
42
  if (rindex (buf, '/') == NULL)
43
    strcat (buf, "./");
44
 
45
  for (i = rindex (buf, '/') - buf + 1; i < max; i++)
46
    buf[i] = 'a';
47
 
48
  buf [i] = 0;
49
 
50
  i = readlink (buf, buf2, sizeof (buf2) - 1);
51
  if (i != -1)
52
     bye ("i", i);
53
 
54
  if (errno != ENAMETOOLONG)
55
    {
56
      perror (buf);
57
      bye ("errno", errno);
58
    }
59
 
60
  printf ("pass\n");
61
  exit (0);
62
}

powered by: WebSVN 2.1.0

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