\begin{slide}{}
\pagetitle{String Arguments}
{\tiny\begin{code}
/* file example.defs */

subsystem example 36270;

#include <mach/std_types.defs>
#include "example_types.defs"

routine stringdemo(
                server  : mach_port_t;
        in      arg1    : string_t;
        out     arg2    : string_t);

/* file example_types.defs */

#include <mach/std_types.defs>
type string_t = c_string[80];
import "example_types.h";

/* file example_types.h */

#ifndef _EXAMPLE_TYPES_H_
#define _EXAMPLE_TYPES_H_

typedef char *string_t;

#endif  _EXAMPLE_TYPES_H_
\end{code}}
\vfill
\end{slide}

\begin{slide}{}
\pagetitle{String Arguments}
Client call:
{\tiny\begin{code}
#include "example.h"

    mach_port_t server;
    char arg2[80];
    kern_return_t kr;

    kr = stringdemo(server, "hi there", arg2);
    printf("I got back %s.\n", arg2);
\end{code}}
Server function:
{\tiny\begin{code}
kern_return_t stringdemo(server, arg1, arg2)
    mach_port_t server;
    char *arg1;                 /* in */
    char *arg2;                 /* out */
{
    printf("I got %s.\n", arg1);
    (void) strcpy(arg2, "hello yourself");
    return KERN_SUCCESS;
}
\end{code}}
\vfill
\end{slide}

\begin{slide}{}
\pagetitle{Variable-Sized String Arguments}
Variable-sized string arguments don't waste message-buffer space
on padding.

{\tiny\begin{code}
/* file example.defs */

subsystem example 36270;

#include <mach/std_types.defs>
#include "example_types.defs"

routine vstringdemo(
                server  : mach_port_t;
        in      arg1    : vstring_t;
        out     arg2    : vstring_t);

/* file example_types.defs */

#include <mach/std_types.defs>
type vstring_t = c_string[*:80];
import "example_types.h";

/* file example_types.h */

#ifndef _EXAMPLE_TYPES_H_
#define _EXAMPLE_TYPES_H_

typedef char *vstring_t;

#endif  _EXAMPLE_TYPES_H_
\end{code}}
\vfill
\end{slide}

\begin{slide}{}
\pagetitle{Variable-Sized String Arguments}
Client call:
{\tiny\begin{code}
#include "example.h"

    mach_port_t server;
    char arg2[80];
    kern_return_t kr;

    kr = vstringdemo(server, "hi there", arg2);
    printf("I got back %s.\n", arg2);
\end{code}}
Server function:
{\tiny\begin{code}
kern_return_t vstringdemo(server, arg1, arg2)
    mach_port_t server;
    char *arg1;                 /* in */
    char *arg2;                 /* out */
{
    printf("I got %s.\n", arg1);
    (void) strcpy(arg2, "hello yourself");
    return KERN_SUCCESS;
}
\end{code}}
\vfill
\end{slide}

\begin{slide}{}
\pagetitle{Variable-Sized In-Line Arguments}
{\tiny\begin{code}
/* file example.defs */

subsystem example 36270;

#include <mach/std_types.defs>
#include "example_types.defs"

routine vinlinedemo(
                server  : mach_port_t;
        in      arg1    : vinline_t;
        out     arg2    : vinline_t);

/* file example_types.defs */

#include <mach/std_types.defs>
/* up to 1024 integers, in-line */
type vinline_t = array[*:1024] of int;
import "example_types.h";

/* file example_types.h */

#ifndef _EXAMPLE_TYPES_H_
#define _EXAMPLE_TYPES_H_

typedef int *vinline_t;

#endif  _EXAMPLE_TYPES_H_
\end{code}}
\vfill
\end{slide}

\begin{slide}{}
\pagetitle{Variable-Sized In-Line Arguments}
Client call:
{\tiny\begin{code}
#include "example.h"

    mach_port_t server;
    int arg1[30], arg2[500];
    unsigned int count1, count2;
    kern_return_t kr;

    count1 = 30;
    count2 = 500;       /* count2 is inout */
    kr = vinlinedemo(server, arg1, count1, &arg2, &count2);
\end{code}}
Server function:
{\tiny\begin{code}
kern_return_t vinlinedemo(server, arg1, arg2)
    mach_port_t server;
    int *arg1;                  /* in */
    unsigned int count1;        /* in */
    int *arg2;                  /* out */
    unsigned int *count2;       /* inout */
{
    /* copy from arg1 to arg2 */

    if (count1 > *count2)
        return KERN_FAILURE;

    bcopy((char *) arg1, (char *) arg2,
          count1 * sizeof *arg1);
    *count2 = count1;
    return KERN_SUCCESS;
}
\end{code}}
\vfill
\end{slide}
