~ubuntu-branches/ubuntu/raring/postfix/raring

« back to all changes in this revision

Viewing changes to src/util/argv.c

Tags: upstream-2.2.6
ImportĀ upstreamĀ versionĀ 2.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
/*
24
24
/*      void    argv_terminate(argvp);
25
25
/*      ARGV    *argvp;
 
26
/*
 
27
/*      void    argv_truncate(argvp, len);
 
28
/*      ARGV    *argvp;
 
29
/*      int     len;
26
30
/* DESCRIPTION
27
31
/*      The functions in this module manipulate arrays of string
28
32
/*      pointers. An ARGV structure contains the following members:
49
53
/*      returns a null pointer.
50
54
/*
51
55
/*      argv_terminate() null-terminates its string array argument.
 
56
/*
 
57
/*      argv_truncate() trucates its argument to the specified
 
58
/*      number of entries, but does not reallocate memory. The
 
59
/*      result is null-terminated.
52
60
/* SEE ALSO
53
61
/*      msg(3) diagnostics interface
54
62
/* DIAGNOSTICS
177
185
     */
178
186
    argvp->argv[argvp->argc] = 0;
179
187
}
 
188
 
 
189
/* argv_truncate - truncate string array */
 
190
 
 
191
void    argv_truncate(ARGV *argvp, int len)
 
192
{
 
193
    char  **cpp;
 
194
 
 
195
    /*
 
196
     * Sanity check.
 
197
     */
 
198
    if (len < 0)
 
199
        msg_panic("argv_truncate: bad length %d", len);
 
200
 
 
201
    if (len < argvp->argc) {
 
202
        for (cpp = argvp->argv + len; cpp < argvp->argv + argvp->argc; cpp++)
 
203
            myfree(*cpp);
 
204
        argvp->argc = len;
 
205
        argvp->argv[argvp->argc] = 0;
 
206
    }
 
207
}