Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strnsave(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                             strnsave(3C)



        _________________________________________________________________
        strnsave                                                 function
        Allocate an area large enough to hold a string.
        _________________________________________________________________


        Calling Sequence

        char *string, *newstring;
        int n;
        newstring = strnsave(string, n);


          where   string is a byte pointer to a character array that
                  ends in null.
                  n specifies the maximum number of characters to
                  copy.
                  newstring is a byte pointer to the area allocated to
                  receive a copy of the string.



        Description

        The strnsave function performs the following:

        *    Allocates from the heap an area of memory large enough to
             hold a specified string.

        *    Moves the string into the allocated area.

        *    Returns a pointer to the area.  This function is the same as
             the strsave function, except that with strsave you don't
             specify the maximum number of characters to copy.

        The include file string.h defines this function.


        Returns

        The strnsave function returns a pointer to the allocated area.
        It return a null if it cannot allocate the area.


        Related Functions

        See also the strsave function.


        Example




        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                             strnsave(3C)



        /* Program test for the strnsave() function */

        #include <string.h>
        #include <stdio.h>
        #define MAX     80

        char  *newloc;
        int    i = 1;

        main(argc, argv)
        int    argc;
        char  *argv[];
        {
            while (i < argc) {
                newloc = strnsave(argv[i], MAX);
                printf("\tStored argv[%d] at %o.\n",
                i, newloc);
                printf("argv[%d] = '%s'\n", i, newloc);
                i++;
            }
        }

        A call to the program test with

        x test Find some addresses.

        generates the output

        Stored argv[1] at 34003703644.
        argv[1] = 'Find'
        Stored argv[2] at 34003677500.
        argv[2] = 'some'
        Stored argv[3] at 34003677344.
        argv[3] = 'addresses.'

        (The locations vary with execution.)


















        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



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