/*
* Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Brian Ginsbach.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "lint.h"
#include "file64.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
/*
* getdate_err is set to one of the following values on error.
*
* 1 The DATEMSK environment variable is null or undefined.
* 2 The template file cannot be opened for reading.
* 3 Failed to get file status information.
* 4 Template file is not a regular file.
* 5 Encountered an error while reading the template file.
* 6 Cannot allocate memory.
* 7 Input string does not match any line in the template.
* 8 Input string is invalid (for example, February 31) or could not
* be represented in a time_t.
*
* Note that on Solaris, getdate_err is possibly a function, to account
* for reentrancy. See the code for getdate_err.c for details.
*/
struct tm *
{
getdate_err = 1;
return (NULL);
}
getdate_err = 3;
return (NULL);
}
getdate_err = 4;
return (NULL);
}
getdate_err = 2;
return (NULL);
}
/* loop through datemsk file */
errno = 0;
/*
* The NetBSD implementation supports a rich flexible file format
* with embedded escapes, etc. We don't need any of that. Solaris
* just reads the template file and (undocumented!) requires that
* each line not exceed 512 bytes, using a fixed buffer. We could
* improve on that, but this may grow the stack unreasonably, so
* we keep it to the same 512 limit. Some day we can be smarter.
* (Note FreeBSD doesn't even have getdate(), and IMO nobody sane
* should be using this crufty API. strptime is better.)
*/
/*
* If the buffer consumed the entire string, then
* the input line was too long. We just check to
* see if the 2nd to last byte is set. If it isn't,
* then we hit a null byte first, and the line is
* short enough.
*/
getdate_err = 5;
return (NULL);
}
/* initialize tmp with sentinels */
break;
errno = 0;
}
getdate_err = 6;
else
getdate_err = 5;
return (NULL);
}
getdate_err = 7;
return (NULL);
}
/*
* This implementation does not accept setting the broken-down time
* to anything other than the localtime(). It is not possible to
* change the scanned timezone with %Z.
*
* Note IRIX and Solaris accept only the current zone for %Z.
* XXX Is there any implementation that matches the standard?
* XXX (Or am I reading the standard wrong?)
*
* Note: Neither XPG 6 (POSIX 2004) nor XPG 7 (POSIX 2008)
* requires strptime(3) support for %Z.
*/
/*
* Given only a weekday find the first matching weekday starting
* with the current weekday and moving into the future.
*/
}
/*
* Given only a month (and no year) find the first matching month
* starting with the current month and moving into the future.
*/
}
/* assume the first of the month */
/*
* XXX This isn't documented! Just observed behavior.
*
* Given the weekday find the first matching weekday
* starting with the weekday of the first day of the
* the month and moving into the future.
*/
}
}
}
/*
* Given no time of day assume the current time of day.
*/
}
/*
* Given an hour and no date, find the first matching hour starting
* with the current hour and moving into the future
*/
}
/*
* Set to 'sane' values; mktime(3) does funny things otherwise.
* No hours, no minutes, no seconds, no service.
*/
/*
* Given only a year the values of month, day of month, day of year,
* week day and is daylight (summer) time are unspecified.
* (Specified on the Solaris man page not POSIX.)
*/
/*
* XXX More undocumented functionality but observed.
*
* Given the weekday find the first matching weekday
* starting with the weekday of the first day of the
* month and moving into the future.
*/
}
}
/*
* Given only the century but no year within, the current year
* is assumed. (Specified on the Solaris man page not POSIX.)
*
* Warning ugly end case
*
* This is more work since strptime(3) doesn't "do the right thing".
*/
}
/*
* mktime() will normalize all values and also check that the
* value will fit into a time_t.
*
* This is only for POSIX correctness. A date >= 1900 is
* really ok, but using a time_t limits things.
*/
getdate_err = 8;
return (NULL);
}
return (rtmp);
}