strace.c revision ae35285a4e0fe9ad6a7ffd73227903966dab4c59
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stropts.h>
#define DATSIZE 8192
#define MAXTID 50
static int errflg = 0; /* set if error in argument parsing */
static int infile = 0; /* set if using standard input for arguments */
static int log;
static char *getarg(void);
static int
{
short ids[2];
if (!ap)
return (-2);
return (-1);
errflg = 1;
return (-2);
}
static char *
getarg(void)
{
static char argbuf[40];
static int eofflg = 0;
char *ap;
int c;
if (eofflg) {
infile = 0;
return (NULL);
}
/*
* Scan to first significant character in standard input.
* If EOF is encountered turn off standard input scanning and
* return NULL
*/
;
if (c == EOF) {
infile = 0;
eofflg++;
return (NULL);
}
/*
* collect token until whitespace is encountered. Don't do anything
* with EOF here as it will be caught the next time around.
*/
while (1) {
*ap++ = c;
c == '\t' || c == EOF) {
*ap = '\0';
return (argbuf);
}
}
}
static int
{
static int index = 1;
/*
* if inside of standard input scan take arguments from there.
*/
if (infile) {
if (errflg)
return (0);
/*
* if the previous operations encountered EOF, infile
* will be set to zero. The trace_ids structure must
* then be loaded from the command line arguments.
* Otherwise, the structure is now valid and should
* be returned.
*/
if (infile)
return (1);
}
/*
* if we get here we are either taking arguments from the
* command line argument list or we hit end of file on standard
* input and should return to finish off the command line arguments
*/
return (0);
/*
* if a '-' is present, start parsing from standard input
*/
infile = 1;
index++;
goto retry;
}
/*
* Parsing from command line, make sure there are
* at least 3 arguments remaining.
*/
return (0);
if (errflg)
return (0);
return (1);
}
int
{
int n;
int ntid;
int val;
int flag;
if (log < 0) {
return (1);
}
ntid = 0;
if (ac == 1) {
ntid++;
} else {
ntid++;
tp++;
}
}
if (errflg)
return (errflg);
return (1);
}
flag = 0;
flag = 0;
}
return (0);
}
static void
{
char *ts;
int *args;
char *ap;
}