File positions are off_t nowdays, not long, so:
long -> off_t strtol -> strtoll fseek -> fseeko NOTE: that fseek not works for >long offsets files per POSIX: [EOVERFLOW] For fseek( ), the resulting file offset would be a value which cannot be represented correctly in an object of type long.
This commit is contained in:
parent
fd818070c8
commit
bd9dc97512
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=82762
@ -52,8 +52,8 @@ struct mapinfo {
|
||||
|
||||
enum STYLE { NOTSET = 0, FBYTES, FLINES, RBYTES, RLINES, REVERSE };
|
||||
|
||||
void forward __P((FILE *, enum STYLE, long, struct stat *));
|
||||
void reverse __P((FILE *, enum STYLE, long, struct stat *));
|
||||
void forward __P((FILE *, enum STYLE, off_t, struct stat *));
|
||||
void reverse __P((FILE *, enum STYLE, off_t, struct stat *));
|
||||
|
||||
int bytes __P((FILE *, off_t));
|
||||
int lines __P((FILE *, off_t));
|
||||
|
@ -58,7 +58,7 @@ static const char rcsid[] =
|
||||
#include <err.h>
|
||||
#include "extern.h"
|
||||
|
||||
static void rlines __P((FILE *, long, struct stat *));
|
||||
static void rlines __P((FILE *, off_t, struct stat *));
|
||||
|
||||
/* defines for inner loop actions */
|
||||
#define USE_SLEEP 0
|
||||
@ -91,7 +91,7 @@ void
|
||||
forward(fp, style, off, sbp)
|
||||
FILE *fp;
|
||||
enum STYLE style;
|
||||
long off;
|
||||
off_t off;
|
||||
struct stat *sbp;
|
||||
{
|
||||
int ch, kq = -1;
|
||||
@ -106,7 +106,7 @@ forward(fp, style, off, sbp)
|
||||
if (S_ISREG(sbp->st_mode)) {
|
||||
if (sbp->st_size < off)
|
||||
off = sbp->st_size;
|
||||
if (fseek(fp, off, SEEK_SET) == -1) {
|
||||
if (fseeko(fp, off, SEEK_SET) == -1) {
|
||||
ierr();
|
||||
return;
|
||||
}
|
||||
@ -137,7 +137,7 @@ forward(fp, style, off, sbp)
|
||||
case RBYTES:
|
||||
if (S_ISREG(sbp->st_mode)) {
|
||||
if (sbp->st_size >= off &&
|
||||
fseek(fp, -off, SEEK_END) == -1) {
|
||||
fseeko(fp, -off, SEEK_END) == -1) {
|
||||
ierr();
|
||||
return;
|
||||
}
|
||||
@ -154,7 +154,7 @@ forward(fp, style, off, sbp)
|
||||
case RLINES:
|
||||
if (S_ISREG(sbp->st_mode))
|
||||
if (!off) {
|
||||
if (fseek(fp, 0L, SEEK_END) == -1) {
|
||||
if (fseeko(fp, (off_t)0, SEEK_END) == -1) {
|
||||
ierr();
|
||||
return;
|
||||
}
|
||||
@ -226,7 +226,7 @@ forward(fp, style, off, sbp)
|
||||
action = USE_SLEEP;
|
||||
} else if (ev->data < 0) {
|
||||
/* file shrank, reposition to end */
|
||||
if (fseek(fp, 0L, SEEK_END) == -1) {
|
||||
if (fseeko(fp, (off_t)0, SEEK_END) == -1) {
|
||||
ierr();
|
||||
return;
|
||||
}
|
||||
@ -266,7 +266,7 @@ forward(fp, style, off, sbp)
|
||||
static void
|
||||
rlines(fp, off, sbp)
|
||||
FILE *fp;
|
||||
long off;
|
||||
off_t off;
|
||||
struct stat *sbp;
|
||||
{
|
||||
struct mapinfo map;
|
||||
|
@ -56,7 +56,7 @@ static const char rcsid[] =
|
||||
#include "extern.h"
|
||||
|
||||
static void r_buf __P((FILE *));
|
||||
static void r_reg __P((FILE *, enum STYLE, long, struct stat *));
|
||||
static void r_reg __P((FILE *, enum STYLE, off_t, struct stat *));
|
||||
|
||||
/*
|
||||
* reverse -- display input in reverse order by line.
|
||||
@ -80,7 +80,7 @@ void
|
||||
reverse(fp, style, off, sbp)
|
||||
FILE *fp;
|
||||
enum STYLE style;
|
||||
long off;
|
||||
off_t off;
|
||||
struct stat *sbp;
|
||||
{
|
||||
if (style != REVERSE && off == 0)
|
||||
@ -111,7 +111,7 @@ static void
|
||||
r_reg(fp, style, off, sbp)
|
||||
FILE *fp;
|
||||
enum STYLE style;
|
||||
long off;
|
||||
off_t off;
|
||||
struct stat *sbp;
|
||||
{
|
||||
struct mapinfo map;
|
||||
|
@ -71,7 +71,7 @@ main(argc, argv)
|
||||
{
|
||||
struct stat sb;
|
||||
FILE *fp;
|
||||
long off;
|
||||
off_t off;
|
||||
enum STYLE style;
|
||||
int ch, first;
|
||||
char *p;
|
||||
@ -91,7 +91,7 @@ main(argc, argv)
|
||||
#define ARG(units, forward, backward) { \
|
||||
if (style) \
|
||||
usage(); \
|
||||
off = strtol(optarg, &p, 10) * (units); \
|
||||
off = strtoll(optarg, &p, 10) * (units); \
|
||||
if (*p) \
|
||||
errx(1, "illegal offset -- %s", optarg); \
|
||||
switch(optarg[0]) { \
|
||||
|
Loading…
Reference in New Issue
Block a user