Deleted Added
sdiff udiff text old ( 72472 ) new ( 72529 )
full compact
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 25 unchanged lines hidden (view full) ---

34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38#if 0
39static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94";
40#endif
41static const char rcsid[] =
42 "$FreeBSD: head/lib/libc/stdio/findfp.c 72472 2001-02-14 05:00:20Z peter $";
43#endif /* LIBC_SCCS and not lint */
44
45#include <sys/param.h>
46#include <machine/atomic.h>
47#include <unistd.h>
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51
52#include <spinlock.h>
53
54#include "libc_private.h"
55#include "local.h"
56#include "glue.h"
57
58int __sdidinit;
59
60#define NDYNAMIC 10 /* add ten more whenever necessary */
61
62#define std(handle, flags, file) \
63FILE handle = {0,0,0,flags,file,{0},0,&handle,__sclose,__sread,__sseek,__swrite}
64/* p r w flags file _bf z cookie close read seek write */
65
66 /* the usual - (stdin + stdout + stderr) */
67static FILE usual[FOPEN_MAX - 3];
68static struct glue uglue = { NULL, FOPEN_MAX - 3, usual };
69
70std(__stdin, __SRD, STDIN_FILENO);
71std(__stdout, __SWR, STDOUT_FILENO);
72std(__stderr, __SWR|__SNBF, STDERR_FILENO);
73
74static struct glue sglue2 = { &uglue, 1, &__stderr };
75static struct glue sglue1 = { &sglue2, 1, &__stdout };
76struct glue __sglue = { &sglue1, 1, &__stdin };
77static struct glue *lastglue = &uglue;
78
79static struct glue * moreglue __P((int));
80
81static spinlock_t thread_lock = _SPINLOCK_INITIALIZER;
82#define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock)
83#define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock)
84
85#if NOT_YET
86#define SET_GLUE_PTR(ptr, val) atomic_set_rel_ptr(&(ptr), (uintptr_t)(val))
87#else
88#define SET_GLUE_PTR(ptr, val) ptr = val
89#endif
90
91static struct glue *
92moreglue(n)
93 int n;
94{
95 struct glue *g;
96 FILE *p;
97 static FILE empty;
98
99 g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE));
100 if (g == NULL)
101 return (NULL);
102 p = (FILE *)ALIGN(g + 1);
103 g->next = NULL;
104 g->niobs = n;
105 g->iobs = p;
106 while (--n >= 0)
107 *p++ = empty;
108 return (g);
109}
110
111/*
112 * Find a free FILE for fopen et al.
113 */
114FILE *
115__sfp()

--- 95 unchanged lines hidden ---