/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*
* this file contains routines for the manipulation of filenames.
* they aren't particularly fast (at least they weren't designed
* stuff for these strings in a central place. most routines in
* logadm that return filenames return a struct fn, and most routines
* that return lists of strings return a struct fn_list.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <libintl.h>
#include <strings.h>
#include "err.h"
#include "fn.h"
/*
* constants controlling how we malloc space. bigger means fewer
* calls to malloc. smaller means less wasted space.
*/
/* info created by fn_new(), private to this module */
struct fn {
int fn_n;
};
/* info created by fn_list_new(), private to this module */
struct fn_list {
};
/*
* fn_new -- create a new filename buffer, possibly with initial contents
*
* use like this:
* struct fn *fnp = fn_new("this is a string");
*/
struct fn *
fn_new(const char *s)
{
/* if passed-in string contains at least 1 non-null character... */
if (s != NULL && *s) {
/* start with buffer filled with passed-in string */
} else {
/* start with empty buffer */
}
return (fnp);
}
/*
* fn_dup -- duplicate a filename buffer
*/
struct fn *
{
return (ret);
}
/*
* fn_dirname -- return the dirname part of a filename
*/
struct fn *
{
char *buf;
return (fn_new("."));
else {
*ptr = '\0';
*ptr = '/';
return (ret);
}
}
/*
* fn_setn -- set the "n" value for a filename
*
* the "n" value is initially -1, and is used by logadm to store
* the suffix for rotated log files. the function fn_list_popoldest()
* looks at these "n" values when sorting filenames to determine which
* old log file is the oldest and should be expired first.
*/
void
{
}
/*
* fn_setstat -- store a struct stat with a filename
*
* the glob functions typically fill in these struct stats since they
* have to stat while globbing anyway. just turned out to be a common
* piece of information that was conveniently stored with the associated
* filename.
*/
void
{
}
/*
* fn_getstat -- return a pointer to the stat info stored by fn_setstat()
*/
struct stat *
{
}
/*
* fn_free -- free a filename buffer
*/
void
{
if (fnp) {
}
}
/*
* fn_renew -- reset a filename buffer
*
* calling fn_renew(fnp, s) is the same as calling:
* fn_free(fnp);
* fn_new(s);
*/
void
{
}
/*
* fn_putc -- append a character to a filename
*
* this is the function that handles growing the filename buffer
* automatically and calling err() if it overflows.
*/
void
{
char *newbuf;
char *src;
char *dst;
/* overflow, allocate more space or die if at FN_MAX */
err(0, "fn buffer overflow");
/* copy string into new buffer */
/* just copy up to wptr, rest is history anyway */
}
}
/*
* fn_puts -- append a string to a filename
*/
void
{
/* non-optimal, but simple! */
while (s != NULL && *s)
}
/*
* fn_putfn -- append a filename buffer to a filename
*/
void
{
int c;
}
/*
* fn_rewind -- reset the "read pointer" to the beginning of a filename
*/
void
{
}
/*
* fn_getc -- "read" the next character of a filename
*/
int
{
return (0);
}
/*
* fn_peekc -- "peek" at the next character of a filename
*/
int
{
return (0);
}
/*
* fn_s -- return a pointer to a null-terminated string containing the filename
*/
char *
{
}
/*
* fn_isgz -- return true if filename is *.gz
*/
{
char *name;
return (B_TRUE);
else
return (B_FALSE);
}
/*
* fn_list_new -- create a new list of filenames
*
* by convention, an empty list is represented by an allocated
* struct fn_list which contains a NULL linked list, rather than
* by a NULL fn_list pointer. in other words:
*
* struct fn_list *fnlp = some_func_returning_a_list();
* if (fn_list_empty(fnlp))
* ...
*
* is preferable to checking if the fnlp returned is NULL.
*/
struct fn_list *
{
return (fnlp);
}
/*
* fn_list_dup -- duplicate a list of filenames
*/
struct fn_list *
{
return (ret);
}
/*
* fn_list_free -- free a list of filenames
*/
void
{
}
/*
* fn_list_adds -- add a string to a list of filenames
*/
void
{
}
/*
* fn_list_addfn -- add a filename (i.e. struct fn *) to a list of filenames
*/
void
{
else {
}
}
/*
* fn_list_rewind -- reset the "read pointer" to the beginning of the list
*/
void
{
}
/*
* fn_list_next -- return the filename at the read pointer and advance it
*/
struct fn *
{
return (ret);
}
/*
* fn_list_addfn_list -- move filenames from fnlp2 to end of fnlp
*
* frees fnlp2 after moving all the filenames off of it.
*/
void
{
/* for each fn in the second list... */
while (fnp2) {
else
/* append it to the first list */
}
/* all the fn's were moved off the second list */
/* done with the second list */
}
/*
* fn_list_appendrange -- append a range of characters to each filename in list
*
* range of characters appended is the character at *s up to but not including
* the character at *limit. NULL termination is not required.
*/
void
{
const char *ptr;
/* for each fn in the list... */
else
/* append the range */
}
}
/*
* fn_list_totalsize -- sum up all the st_size fields in the stat structs
*/
{
return (ret);
}
/*
* fn_list_popoldest -- remove oldest file from list and return it
*
* this function uses the "n" values (set by fn_setn()) to determine
* which file is oldest, or when there's a tie it turns to the modification
* times in the stat structs, or when there's still a tie lexical sorting.
*/
struct fn *
{
return (NULL);
/* oldest file is ret, remove it from list */
} else {
break;
}
}
}
return (ret);
}
/*
* fn_list_empty -- true if the list is empty
*/
{
}
/*
* fn_list_count -- return number of filenames in list
*/
int
{
int ret = 0;
/*
* if this operation were more common, we'd cache the count
* in the struct fn_list, but it isn't very common so we just
* count 'em up here
*/
ret++;
return (ret);
}