usr/src/cmd/fm/eversholt/common/eftwrite.c
changeset 2538 b5894d78c55a
parent 0 68f95e015346
child 5609 6c18074bcfad
equal deleted inserted replaced
2537:0607d7a40022 2538:b5894d78c55a
     1 /*
     1 /*
     2  * CDDL HEADER START
     2  * CDDL HEADER START
     3  *
     3  *
     4  * The contents of this file are subject to the terms of the
     4  * The contents of this file are subject to the terms of the
     5  * Common Development and Distribution License, Version 1.0 only
     5  * Common Development and Distribution License (the "License").
     6  * (the "License").  You may not use this file except in compliance
     6  * You may not use this file except in compliance with the License.
     7  * with the License.
       
     8  *
     7  *
     9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
    10  * or http://www.opensolaris.org/os/licensing.
     9  * or http://www.opensolaris.org/os/licensing.
    11  * See the License for the specific language governing permissions
    10  * See the License for the specific language governing permissions
    12  * and limitations under the License.
    11  * and limitations under the License.
    18  * information: Portions Copyright [yyyy] [name of copyright owner]
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
    19  *
    18  *
    20  * CDDL HEADER END
    19  * CDDL HEADER END
    21  */
    20  */
    22 /*
    21 /*
    23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
    22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
    24  * Use is subject to license terms.
    23  * Use is subject to license terms.
    25  *
    24  *
    26  * eftwrite.c -- routines for writing .eft files
    25  * eftwrite.c -- routines for writing .eft files
    27  *
    26  *
    28  * this module emits the table resulting from compilation of the
    27  * this module emits the table resulting from compilation of the
    33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
    32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
    34 
    33 
    35 #include <stdio.h>
    34 #include <stdio.h>
    36 #include <string.h>
    35 #include <string.h>
    37 #include <strings.h>
    36 #include <strings.h>
    38 #include <time.h>
       
    39 #include <unistd.h>
    37 #include <unistd.h>
    40 #include <errno.h>
    38 #include <errno.h>
    41 #include "out.h"
    39 #include "out.h"
    42 #include "stats.h"
    40 #include "stats.h"
    43 #include "stable.h"
    41 #include "stable.h"
    63 
    61 
    64 void
    62 void
    65 eftwrite_init(void)
    63 eftwrite_init(void)
    66 {
    64 {
    67 	Outbytes = stats_new_counter("eftwrite.total", "bytes written", 1);
    65 	Outbytes = stats_new_counter("eftwrite.total", "bytes written", 1);
    68 }
       
    69 
       
    70 static const char *
       
    71 mygetlogin(void)
       
    72 {
       
    73 	const char *result = getlogin();
       
    74 	static char id[100];
       
    75 
       
    76 	if (result != NULL)
       
    77 		return (result);
       
    78 
       
    79 	(void) snprintf(id, 100, "uid:%ld", getuid());
       
    80 	return (id);
       
    81 }
    66 }
    82 
    67 
    83 /*ARGSUSED*/
    68 /*ARGSUSED*/
    84 static void
    69 static void
    85 ident_lencalc(const char *s, void *rhs, void *arg)
    70 ident_lencalc(const char *s, void *rhs, void *arg)
   119 	FILE *tfp;
   104 	FILE *tfp;
   120 	struct eftheader hdr;
   105 	struct eftheader hdr;
   121 #define	BUFLEN	8192
   106 #define	BUFLEN	8192
   122 	char buf[BUFLEN];
   107 	char buf[BUFLEN];
   123 	int cc;
   108 	int cc;
   124 	time_t clock;
       
   125 
   109 
   126 	if ((tfp = tmpfile()) == NULL)
   110 	if ((tfp = tmpfile()) == NULL)
   127 		out(O_DIE|O_SYS, "cannot create temporary file");
   111 		out(O_DIE|O_SYS, "cannot create temporary file");
   128 
   112 
   129 	/* XXX switch stdout to tfp temporarily */
   113 	/* XXX switch stdout to tfp temporarily */
   142 	hdr.minor = EFT_HDR_MINOR;
   126 	hdr.minor = EFT_HDR_MINOR;
   143 	hdr.cmajor = VERSION_MAJOR;
   127 	hdr.cmajor = VERSION_MAJOR;
   144 	hdr.cminor = VERSION_MINOR;
   128 	hdr.cminor = VERSION_MINOR;
   145 	hdr.identlen = Identlen;
   129 	hdr.identlen = Identlen;
   146 	hdr.dictlen = Dictlen;
   130 	hdr.dictlen = Dictlen;
   147 	(void) time(&clock);
       
   148 	if (gethostname(buf, BUFLEN) < 0)
       
   149 		out(O_DIE|O_SYS, "gethostname");
       
   150 	buf[BUFLEN - 1] = '\0';
   131 	buf[BUFLEN - 1] = '\0';
   151 	(void) snprintf(hdr.comment, EFT_HDR_MAXCOMMENT,
   132 	(void) snprintf(hdr.comment, EFT_HDR_MAXCOMMENT,
   152 	    "Built using esc-%d.%d by %s on %s at %s\tArgs: \"%s\"\n",
   133 	    "Built using esc-%d.%d\tArgs: \"%s\"\n", VERSION_MAJOR,
   153 	    VERSION_MAJOR, VERSION_MINOR, mygetlogin(), buf, ctime(&clock),
   134 	    VERSION_MINOR, Args);
   154 	    Args);
       
   155 
   135 
   156 	if ((fp = fopen(fname, "w")) == NULL)
   136 	if ((fp = fopen(fname, "w")) == NULL)
   157 		out(O_DIE|O_SYS, "can't open output file: %s", fname);
   137 		out(O_DIE|O_SYS, "can't open output file: %s", fname);
   158 
   138 
   159 	while ((cc = fread(buf, 1, BUFLEN, tfp)) > 0) {
   139 	while ((cc = fread(buf, 1, BUFLEN, tfp)) > 0) {