Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ XtNewString(3x) — HP-UX ANSI C A.09.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

XtMalloc(1)

XtFree(1)

XtNew(1)

 

NAME

XtNewString − copy an instance of a string. 

Synopsis

String XtNewString(string)

    String string;

Inputs

stringSpecifies a NULL-terminated string. 

Returns

A copy of string in allocated memory. 

Description

XtNewString() allocates enough memory to hold a copy of the specified string and copies the string into that memory.  If there is insufficient memory to allocate the new block, XtNewString() prints an error message and terminates the application by calling XtErrorMsg(). 

Usage

Memory allocated with XtNewString() must be deallocated with XtFree().  To simply allocate a specified amount of memory, use XtMalloc().  To allocate enough memory for one instance of a specified type, use XtNew(). 

Example

You might use XtNewString() in a situation like this:

If you copy it, however, you can do anything you like with it, as long as you remember to free it when you are done with it. 

Background

XtNewString() is defined as the following macro:

#define XtNewString(str) #define XtNewString(str)     ((str) != NULL ? (strcpy(XtMalloc((unsigned)strlen(str) + 1),
    str)) : NULL)

See Also

XtMalloc(1), XtFree(1), XtNew(1). 

Copyright O’Reilly & Assoc.  —  X Toolkit Intrinsics Reference Manual © O’Reilly & Associates

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026