---
name: "astsa"
section: "3"
platform: "macos"
package: "ksh"
version: "42"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/astsa"
---

# astsa(3)

standalone libast support

## NAME

astsa - standalone libast support

## SYNOPSIS

```
#include <ast.h>
#include <ccode.h>
#include <error.h>
#include <option.h>
#include <stk.h>
```

## DESCRIPTION

**astsa** is a standalone subset of [**ast**(3)](/ast/3.md) that requires only [**cdt**(3)](/cdt/3.md) and [**sfio**(3)](/sfio/3.md).

**\<ast.h\>** includes **\<ast\_common.h\>**, **\<stdarg.h\>** or **\<varargs.h\>**, **\<sfio.h\>**, **\<limits.h\>**, and **\<limits.h\>** and **\<unistd.h\>** if supported by the local system.

The macros and functions provided by **\<ast.h\>** are described below. The other headers are described in **ccode**(3), [**error**(3)](/error/3.md), [**optget**(3)](/optget/3.md), and [**stk**(3)](/stk/3.md).

## MACROS

### size\_t elementsof(*x*)

Evaluates to the number of elements in the array variable *x*.

### *type*\* newof(void\* old, *type*, size\_t *elements*, size\_t *extra*)

Equivalent to (*type*\*)realloc((char\*)*old*,sizeof(*type*)\**elements*+*extra*) if *old*!=0 and (*type*\*)calloc(1,sizeof(*type*)\**elements*+*extra*) otherwise.

### *type*\* oldof(void\* old, *type*, size\_t *elements*, size\_t *extra*)

Equivalent to (*type*\*)realloc((char\*)*old*,sizeof(*type*)\**elements*+*extra*) if *old*!=0 and (*type*\*)malloc(1,sizeof(*type*)\**elements*+*extra*) otherwise.

### size\_t roundof(*x*,*y*)

Evaluates to *x* rounded up to the next power of 2 boundary *y*.

### int ssizeof(*x*)

Equivalent to (int)sizeof(*x*).

### int streq(*a*,*b*)

Equivalent to (\*(*a*)==\*(*b*)&&strcmp(*a*,*b*)==0).

### int strneq(*a*,*b*,*n*)

Equivalent to (\*(*a*)==\*(*b*)&&strncmp(*a*,*b*,*n*)==0).

## FUNCTIONS

### void astwinsize(int *fd*, int\* *plines*, int\* *pcolumns*)

If *plines*!=0 then \**plines* is set to the number of lines on the tty device corresponding to *fd*. If *pcolumns*!=0 then \**pcolumns* is set to the number of columns on the tty device corresponding to *fd*. The default if *fd* is not a terminal device, or if *fd* queries fail, is 24 lines and 80 columns.

### char\* fmterror(int *errno*)

Returns the error message text corresponding to the [**errno**(3)](/errno/3.md) *errno*.

### char\* strerror(int *errno*)

Equivalent to fmterror(*errno*).

### int strgrpmatch(const char\* *string*, const char\* *pattern*, int\* *sub*, int *nsub*, int *flags*)

Matches the null terminated *string* against the null terminated [**ksh**(1)](/ksh/1.md) augmented *pattern*. If *sub*!=0 then *sub*\[2\**i*\] is set to the start offset and *sub*\[2\**i*+1\] is set to the end offset of the *i*-th parenthesized subexpression. *nsub* is 1/2 the number of elements in *sub*. *flags* controls the matching:

- STR\_MAXIMAL:

  Maximal match. The default is minimal (first) match.

- STR\_LEFT:

  Implicit left anchor.

- STR\_RIGHT:

  Implicit right anchor.

- STR\_ICASE:

  Ignore case.

- STR\_GROUP:

  (\|&) inside \[@\|\*\|+{n,m}\](...) only.

### int strmatch(const char\* *string*, const char\* *pattern*, int\* *sub*, int *nsub*, int *flags*)

Equivalent to strgrpmatch(*string*,*pattern*,0,0,STR\_MAXIMAL\|STR\_LEFT\|STR\_RIGHT).

## SEE ALSO

[**ast**(3)](/ast/3.md), **ccode**(3), [**cdt**(3)](/cdt/3.md), [**error**(3)](/error/3.md), [**malloc**(3)](/malloc/3.md), **option**(3), [**sfio**(3)](/sfio/3.md), [**stk**(3)](/stk/3.md)
