Deleted Added
full compact
findfp.c (72472) findfp.c (72529)
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[] =
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 $";
42 "$FreeBSD: head/lib/libc/stdio/findfp.c 72529 2001-02-16 06:11:22Z imp $";
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
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
62#define std(flags, file) \
63 {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \
64 {0}, __sFX + file}
65 /* p r w flags file _bf z cookie close read seek write */
66 /* _ub _extra */
66 /* the usual - (stdin + stdout + stderr) */
67static FILE usual[FOPEN_MAX - 3];
68static struct glue uglue = { NULL, FOPEN_MAX - 3, usual };
69
67 /* the usual - (stdin + stdout + stderr) */
68static FILE usual[FOPEN_MAX - 3];
69static struct glue uglue = { NULL, FOPEN_MAX - 3, usual };
70
70std(__stdin, __SRD, STDIN_FILENO);
71std(__stdout, __SWR, STDOUT_FILENO);
72std(__stderr, __SWR|__SNBF, STDERR_FILENO);
71static struct __sFILEX __sFX[3];
73
72
74static struct glue sglue2 = { &uglue, 1, &__stderr };
75static struct glue sglue1 = { &sglue2, 1, &__stdout };
76struct glue __sglue = { &sglue1, 1, &__stdin };
73FILE __sF[3] = {
74 std(__SRD, STDIN_FILENO),
75 std(__SWR, STDOUT_FILENO),
76 std(__SWR|__SNBF, STDERR_FILENO)
77};
78
79struct glue __sglue = { &uglue, 3, __sF };
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;
80static struct glue *lastglue = &uglue;
81
82static struct glue * moreglue __P((int));
83
84static spinlock_t thread_lock = _SPINLOCK_INITIALIZER;
85#define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock)
86#define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock)
87
88#if NOT_YET
89#define SET_GLUE_PTR(ptr, val) atomic_set_rel_ptr(&(ptr), (uintptr_t)(val))
90#else
91#define SET_GLUE_PTR(ptr, val) ptr = val
92#endif
93
94static struct glue *
95moreglue(n)
96 int n;
97{
98 struct glue *g;
96 FILE *p;
97 static FILE empty;
99 static FILE empty;
100 static struct __sFILEX emptyx;
101 FILE *p;
102 struct __sFILEX *fx;
98
103
99 g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE));
104 g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) +
105 n * sizeof(struct __sFILEX));
100 if (g == NULL)
101 return (NULL);
102 p = (FILE *)ALIGN(g + 1);
106 if (g == NULL)
107 return (NULL);
108 p = (FILE *)ALIGN(g + 1);
109 fx = (struct __sFILEX *)&p[n];
103 g->next = NULL;
104 g->niobs = n;
105 g->iobs = p;
110 g->next = NULL;
111 g->niobs = n;
112 g->iobs = p;
106 while (--n >= 0)
107 *p++ = empty;
113 while (--n >= 0) {
114 *p = empty;
115 p->_extra = fx;
116 *p->_extra = emptyx;
117 p++, fx++;
118 }
108 return (g);
109}
110
111/*
112 * Find a free FILE for fopen et al.
113 */
114FILE *
115__sfp()

--- 95 unchanged lines hidden ---
119 return (g);
120}
121
122/*
123 * Find a free FILE for fopen et al.
124 */
125FILE *
126__sfp()

--- 95 unchanged lines hidden ---