Deleted Added
full compact
memalloc.c (213811) memalloc.c (213814)
1/*-
2 * Copyright (c) 1991, 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 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1991, 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 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 213811 2010-10-13 22:18:03Z obrien $");
39__FBSDID("$FreeBSD: head/bin/sh/memalloc.c 213814 2010-10-13 23:29:09Z obrien $");
40
41#include <sys/param.h>
42#include "shell.h"
43#include "output.h"
44#include "memalloc.h"
45#include "error.h"
46#include "mystring.h"
47#include "expand.h"

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

290 * the string, the user should use grabstack to allocate the space, and
291 * then call ungrabstr(p) to return to the previous mode of operation.
292 *
293 * USTPUTC is like STPUTC except that it doesn't check for overflow.
294 * CHECKSTACKSPACE can be called before USTPUTC to ensure that there
295 * is space for at least one character.
296 */
297
40
41#include <sys/param.h>
42#include "shell.h"
43#include "output.h"
44#include "memalloc.h"
45#include "error.h"
46#include "mystring.h"
47#include "expand.h"

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

290 * the string, the user should use grabstack to allocate the space, and
291 * then call ungrabstr(p) to return to the previous mode of operation.
292 *
293 * USTPUTC is like STPUTC except that it doesn't check for overflow.
294 * CHECKSTACKSPACE can be called before USTPUTC to ensure that there
295 * is space for at least one character.
296 */
297
298static char *
299growstrstackblock(int n)
300{
301 growstackblock();
302 sstrnleft = stackblocksize() - n;
303 return stackblock() + n;
304}
298
299char *
300growstackstr(void)
301{
302 int len;
303
304 len = stackblocksize();
305 if (herefd >= 0 && len >= 1024) {
306 xwrite(herefd, stackblock(), len);
305
306char *
307growstackstr(void)
308{
309 int len;
310
311 len = stackblocksize();
312 if (herefd >= 0 && len >= 1024) {
313 xwrite(herefd, stackblock(), len);
307 sstrnleft = len - 1;
314 sstrnleft = len;
308 return stackblock();
309 }
315 return stackblock();
316 }
310 growstackblock();
311 sstrnleft = stackblocksize() - len - 1;
312 return stackblock() + len;
317 return growstrstackblock(len);
313}
314
315
316/*
317 * Called from CHECKSTRSPACE.
318 */
319
320char *
321makestrspace(void)
322{
323 int len;
324
325 len = stackblocksize() - sstrnleft;
318}
319
320
321/*
322 * Called from CHECKSTRSPACE.
323 */
324
325char *
326makestrspace(void)
327{
328 int len;
329
330 len = stackblocksize() - sstrnleft;
326 growstackblock();
327 sstrnleft = stackblocksize() - len;
328 return stackblock() + len;
331 return growstrstackblock(len);
329}
330
331
332
333void
334ungrabstackstr(char *s, char *p)
335{
336 stacknleft += stacknxt - s;
337 stacknxt = s;
338 sstrnleft = stacknleft - (p - s);
339}
332}
333
334
335
336void
337ungrabstackstr(char *s, char *p)
338{
339 stacknleft += stacknxt - s;
340 stacknxt = s;
341 sstrnleft = stacknleft - (p - s);
342}