open-src/app/xlock/sun-src/usleep.c
author X gate hg captive account <xhg@xserver.us.oracle.com>
Wed, 19 Aug 2015 13:48:41 -0700
changeset 1484 bc8922b8e1d2
parent 1233 1134c9fd2fe6
permissions -rw-r--r--
Added tag s11u3_30 for changeset 221e9d9cc9cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
546
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     1
/*
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     2
 * Copyright (c) 1988-91 by Patrick J. Naughton.
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     3
 *
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     4
 * Permission to use, copy, modify, and distribute this software and its
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     5
 * documentation for any purpose and without fee is hereby granted,
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     6
 * provided that the above copyright notice appear in all copies and that
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     7
 * both that copyright notice and this permission notice appear in
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     8
 * supporting documentation.
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
     9
 *
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    10
 * This file is provided AS IS with no warranties of any kind.  The author
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    11
 * shall have no liability with respect to the infringement of copyrights,
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    12
 * trade secrets or any patents by this file or any part thereof.  In no
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    13
 * event will the author be liable for any lost revenue or profits or
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    14
 * other special, indirect and consequential damages.
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    15
 */
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    16
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    17
/*
1233
1134c9fd2fe6 7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    18
 * Copyright (c) 1990, 2011, Oracle and/or its affiliates. All rights reserved.
546
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    19
 *
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    20
 * Permission is hereby granted, free of charge, to any person obtaining a
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    21
 * copy of this software and associated documentation files (the "Software"),
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    22
 * to deal in the Software without restriction, including without limitation
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    23
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    24
 * and/or sell copies of the Software, and to permit persons to whom the
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    25
 * Software is furnished to do so, subject to the following conditions:
546
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    26
 *
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    27
 * The above copyright notice and this permission notice (including the next
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    28
 * paragraph) shall be included in all copies or substantial portions of the
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    29
 * Software.
546
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    30
 *
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    31
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    32
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    33
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    34
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    35
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    36
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 907
diff changeset
    37
 * DEALINGS IN THE SOFTWARE.
546
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    38
 */
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    39
/*-
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    40
 * usleep.c - OS dependant implementation of usleep().
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    41
 *
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    42
 * Copyright (c) 1991 by Patrick J. Naughton.
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    43
 *
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    44
 * Revision History:
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    45
 * 30-Aug-90: written.
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    46
 *
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    47
 */
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    48
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    49
#include "xlock.h"
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    50
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    51
#ifndef sun  /* Solaris provides in libc */
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    52
int
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    53
usleep(usec)
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    54
    unsigned long usec;
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    55
{
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    56
#ifdef SYSV
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    57
    poll((struct pollfd *) 0, (size_t) 0, usec / 1000);	/* ms resolution */
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    58
#else
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    59
    struct timeval timeout;
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    60
    timeout.tv_usec = usec % (unsigned long) 1000000;
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    61
    timeout.tv_sec = usec / (unsigned long) 1000000;
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    62
    select(0, (void *) 0, (void *) 0, (void *) 0, &timeout);
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    63
#endif
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    64
    return 0;
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    65
}
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    66
#endif
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    67
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    68
/*
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    69
 * returns the number of seconds since 01-Jan-70.
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    70
 * This is used to control rate and timeout in many of the animations.
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    71
 */
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    72
long
1233
1134c9fd2fe6 7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents: 943
diff changeset
    73
seconds(void)
546
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    74
{
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    75
    struct timeval now;
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    76
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    77
    gettimeofday(&now, (struct timezone *) 0);
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    78
    return now.tv_sec;
f3f84c886c69 6741687 Port xlock to open src tree
Mahmood Ali <Mahmood.Ali@Sun.COM>
parents:
diff changeset
    79
}