cmp.c revision 127958
1234353Sdim/* 2234353Sdim * Copyright (c) 1989, 1993 3193323Sed * The Regents of the University of California. All rights reserved. 4193323Sed * 5193323Sed * This code is derived from software contributed to Berkeley by 6193323Sed * Michael Fischbein. 7234353Sdim * 8193323Sed * Redistribution and use in source and binary forms, with or without 9193323Sed * modification, are permitted provided that the following conditions 10193323Sed * are met: 11193323Sed * 1. Redistributions of source code must retain the above copyright 12193323Sed * notice, this list of conditions and the following disclaimer. 13193323Sed * 2. Redistributions in binary form must reproduce the above copyright 14193323Sed * notice, this list of conditions and the following disclaimer in the 15193323Sed * documentation and/or other materials provided with the distribution. 16193323Sed * 4. Neither the name of the University nor the names of its contributors 17193323Sed * may be used to endorse or promote products derived from this software 18193323Sed * without specific prior written permission. 19193323Sed * 20193323Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23193323Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26218893Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27193323Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30218893Sdim * SUCH DAMAGE. 31193323Sed */ 32243830Sdim 33243830Sdim#if 0 34243830Sdim#ifndef lint 35193323Sedstatic char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93"; 36193323Sed#endif /* not lint */ 37193323Sed#endif 38193323Sed#include <sys/cdefs.h> 39193323Sed__FBSDID("$FreeBSD: head/bin/ls/cmp.c 127958 2004-04-06 20:06:54Z markm $"); 40193323Sed 41193323Sed 42193323Sed#include <sys/types.h> 43193323Sed#include <sys/stat.h> 44193323Sed 45193323Sed#include <fts.h> 46193323Sed#include <string.h> 47193323Sed 48193323Sed#include "ls.h" 49193323Sed#include "extern.h" 50193323Sed 51193323Sedint 52193323Sednamecmp(const FTSENT *a, const FTSENT *b) 53193323Sed{ 54193323Sed return (strcoll(a->fts_name, b->fts_name)); 55193323Sed} 56193323Sed 57193323Sedint 58193323Sedrevnamecmp(const FTSENT *a, const FTSENT *b) 59193323Sed{ 60193323Sed return (strcoll(b->fts_name, a->fts_name)); 61193323Sed} 62193323Sed 63193323Sedint 64193323Sedmodcmp(const FTSENT *a, const FTSENT *b) 65193323Sed{ 66243830Sdim return (b->fts_statp->st_mtime - a->fts_statp->st_mtime); 67193323Sed} 68193323Sed 69195340Sedint 70234353Sdimrevmodcmp(const FTSENT *a, const FTSENT *b) 71193323Sed{ 72193323Sed return (a->fts_statp->st_mtime - b->fts_statp->st_mtime); 73195340Sed} 74239462Sdim 75195340Sedint 76195340Sedacccmp(const FTSENT *a, const FTSENT *b) 77239462Sdim{ 78195340Sed return (b->fts_statp->st_atime - a->fts_statp->st_atime); 79193323Sed} 80193323Sed 81195340Sedint 82239462Sdimrevacccmp(const FTSENT *a, const FTSENT *b) 83195340Sed{ 84195340Sed return (a->fts_statp->st_atime - b->fts_statp->st_atime); 85193323Sed} 86193323Sed 87193323Sedint 88195340Sedstatcmp(const FTSENT *a, const FTSENT *b) 89193323Sed{ 90234353Sdim return (b->fts_statp->st_ctime - a->fts_statp->st_ctime); 91193323Sed} 92193323Sed 93193323Sedint 94239462Sdimrevstatcmp(const FTSENT *a, const FTSENT *b) 95234353Sdim{ 96234353Sdim return (a->fts_statp->st_ctime - b->fts_statp->st_ctime); 97234353Sdim} 98234353Sdim