1/*
2 * Copyright (c) 2006 Apple Inc.  All Rights Reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29
30#ifdef	__sun
31#pragma ident	"@(#)lmbench_openclose.c	1.4	06/21/06 Apple Inc."
32#endif
33
34
35#include <unistd.h>
36#include <stdlib.h>
37#include <stdio.h>
38#include <sys/types.h>
39#include <sys/stat.h>
40#include <fcntl.h>
41
42#include "../libmicro.h"
43
44#define	DEFF			"/dev/null"
45static char			*optf = DEFF;
46
47int
48benchmark_init()
49{
50
51	(void) sprintf(lm_optstr, "f:");
52
53	lm_tsdsize = 0;
54
55	(void) sprintf(lm_usage,
56	    "       [-f file-to-stat (default %s)]\n"
57	    "notes: measures stat()\n",
58	    DEFF);
59
60	return (0);
61}
62
63int
64benchmark_optswitch(int opt, char *optarg)
65{
66	switch (opt) {
67	case 'f':
68		optf = optarg;
69		break;
70	default:
71		return (-1);
72	}
73	return (0);
74}
75
76/*ARGSUSED*/
77int
78benchmark(void *tsd, result_t *res)
79{
80	int			i;
81	int			fd;
82
83	res->re_errors = 0;
84
85/*
86 * The libmicro test uses a for loop as below:
87 *   for (i = 0; i < lm_optB; i++) {
88 *
89 * we can probably get away with using lm_optB
90 * in the while loop below
91 *
92 */
93 	i = 0;
94
95	while (i++ < lm_optB) {
96		fd = open(optf, 0);
97		if (fd == -1) {
98			res->re_errors++;
99		}
100		close(fd);
101	}
102
103	res->re_count += lm_optB;
104
105	return (0);
106}
107