pc_subr.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1989, 1998 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifndef KERNEL
#define KERNEL
#endif
#include <sys/sysmacros.h>
/*
* Structure returned by gmtime and localtime calls (see ctime(3)).
*/
struct tm {
short tm_sec;
short tm_min;
short tm_hour;
short tm_mday;
short tm_mon;
short tm_year;
short tm_wday;
short tm_yday;
short tm_isdst;
};
int pc_validchar(char);
static int dysize(int);
/* The cm struct defines tm_year relative to 1900 */
#define YEAR_ZERO 1900
/*
* convert timestruct to pctime
*/
void
{
}
/*
* convert pctime to timeval
*/
void
{
}
/*
* This routine converts time as follows.
* The epoch is 0000 Jan 1 1970 GMT.
* The argument time is in seconds since then.
* The localtime(t) entry returns a pointer to an array
* containing
* seconds (0-59)
* minutes (0-59)
* hours (0-23)
* day of month (1-31)
* month (0-11)
* year-1900
* weekday (0-6, Sun is 0)
* day of the year
* daylight savings flag
*
* The routine calls the system to determine the local
* timezone and whether Daylight Saving Time is permitted locally.
* (DST is then determined by the current local rules)
*
* The routine does not work
* in Saudi Arabia which runs on Solar time.
*
*/
static int dmsize[12] =
{
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
};
/*
* The following table is used for 1974 and 1975 and
* gives the day number of the first day after the Sunday of the
* change.
*/
struct dstab {
int dayyr;
int daylb;
int dayle;
};
1974, 5, 333, /* 1974: Jan 6 - last Sun. in Nov */
1975, 58, 303, /* 1975: Last Sun. in Feb - last Sun in Oct */
0, 119, 303, /* all other years: end Apr - end Oct */
};
1970, 400, 0, /* 1970: no daylight saving at all */
1971, 303, 0, /* 1971: daylight saving from Oct 31 */
1972, 303, 58, /* 1972: Jan 1 -> Feb 27 & Oct 31 -> dec 31 */
0, 303, 65, /* others: -> Mar 7, Oct 31 -> */
};
/*
* The European tables ... based on hearsay
* Believed correct for:
* WE: Great Britain, Ireland, Portugal
* ME: Belgium, Luxembourg, Netherlands, Denmark, Norway,
* Austria, Poland, Czechoslovakia, Sweden, Switzerland,
* DDR, DBR, France, Spain, Hungary, Italy, Jugoslavia
* Eastern European dst is unknown, we'll make it ME until someone speaks up.
* EE: Bulgaria, Finland, Greece, Rumania, Turkey, Western Russia
*/
1983, 86, 303, /* 1983: end March - end Oct */
1984, 86, 303, /* 1984: end March - end Oct */
1985, 86, 303, /* 1985: end March - end Oct */
0, 400, 0, /* others: no daylight saving at all ??? */
};
1983, 86, 272, /* 1983: end March - end Sep */
1984, 86, 272, /* 1984: end March - end Sep */
1985, 86, 272, /* 1985: end March - end Sep */
0, 400, 0, /* others: no daylight saving at all ??? */
};
static struct dayrules {
int dst_type; /* number obtained from system */
int dst_hrs; /* hours to add when dst on */
} dayrules [] = {
-1,
};
static struct tm *
{
int dayno;
int year;
int copyt;
break;
break;
}
}
case NTH:
if (!(
return (ct);
}
break;
case STH:
if (!(
return (ct);
}
break;
default:
return (ct);
}
}
return (ct);
}
/*
* The argument is a 0-origin day number.
* The value is the day number of the first
* Sunday on or after the day.
*/
static int
{
if (d >= 58)
}
static int
dysize(int y)
{
if (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
return (366);
return (365);
}
static struct tm *
{
short *tp;
/*
* break initial number into days
*/
if (hms < 0) {
hms += 86400;
day -= 1;
}
/*
* generate hours:minutes:seconds
*/
d1 /= 60;
/*
* day is the day number.
* generate day of the week.
* The addend is 4 mod 7 (1/1/1970 was Thursday)
*/
/*
* year number
*/
if (day >= 0)
else
/*
* generate month
*/
return (&xtime);
}
/*
* convert year, month, day, hour, minute, sec to (int)time.
*/
static time_t
{
int i;
return (0);
}
ct = 0;
/* Leap year */
ct++;
while (--i)
/* convert to GMT assuming local time */
/* now fix up local daylight time */
return (ct);
}
/*
* Determine whether a character is valid for a pc 8.3 file system file name.
* The Windows 95 Resource Kit claims that these are valid:
* uppercase letters and numbers
* blank
* ASCII characters greater than 127
* $%'-_@~`!()^#&
* Long file names can also have
* lowercase letters
* +,;=[]
*/
int
pc_validchar(char c)
{
char *cp;
int n;
static char valtab[] = {
"$#&@!%()-{}<>`_^~|' "
};
/*
* Should be "$#&@!%()-{}`_^~' " ??
* From experiment in DOSWindows, *+=|\[];:",<>.?/ are illegal.
* See IBM DOS4.0 Tech Ref. B-57.
*/
if (c >= 'A' && c <= 'Z')
return (1);
if (c >= '0' && c <= '9')
return (1);
n = sizeof (valtab);
while (n--) {
if (c == *cp++)
return (1);
}
return (0);
}
/*
* Determine whether a character is valid for a pc 8.3 file system file name.
* The Windows 95 Resource Kit claims that these are valid:
* uppercase letters and numbers
* blank
* ASCII characters greater than 127
* $%'-_@~`!()^#&
* Long file names can also have
* lowercase letters
* +,;=[].
*/
int
pc_valid_lfn_char(char c)
{
char *cp;
int n;
static char valtab[] = {
"+,;=[].$#&@!%()-{}<>`_^~|' "
};
if (c >= 'a' && c <= 'z')
return (1);
if (c >= 'A' && c <= 'Z')
return (1);
if (c >= '0' && c <= '9')
return (1);
n = sizeof (valtab);
while (n--) {
if (c == *cp++)
return (1);
}
return (0);
}
int
pc_valid_long_fn(char *namep)
{
char *tmp;
if (!pc_valid_lfn_char(*tmp))
return (0);
return (0);
return (1);
}
int
{
int i;
char c;
i = PCFNAMESIZE;
while (i-- && ((c = *fname) != ' ')) {
if (!(c == '.' || pc_validchar(c))) {
return (-1);
}
if (foldcase)
else
*tp++ = c;
fname++;
}
if (*ext != ' ') {
*tp++ = '.';
i = PCFEXTSIZE;
while (i-- && ((c = *ext) != ' ')) {
if (!pc_validchar(c)) {
return (-1);
}
if (foldcase)
else
*tp++ = c;
ext++;
}
}
*tp = '\0';
return (0);
}