~ubuntu-branches/ubuntu/oneiric/sg3-utils/oneiric

« back to all changes in this revision

Viewing changes to utils/hxascdmp.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-11-05 20:42:13 UTC
  • mfrom: (5.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091105204213-ug7wrb6m7l9kmvyg
Tags: 1.28-2
* QA upload.
* Add libsgutils2-2.symbols.kfreebsd. Some of the symbols are Linux
  specific causing FTBFS on kfreebsd.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2004-2008 Douglas Gilbert.
 
2
 * Copyright (c) 2004-2009 Douglas Gilbert.
3
3
 * All rights reserved.
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
39
39
 
40
40
static int bytes_per_line = DEF_BYTES_PER_LINE;
41
41
 
42
 
static const char * version_str = "1.10 20080321";
 
42
static const char * version_str = "1.13 20090510";
43
43
 
44
44
#define CHARS_PER_HEX_BYTE 3
45
45
#define BINARY_START_COL 6
46
46
#define MAX_LINE_LENGTH 257
47
47
 
48
48
 
 
49
#ifdef SG_LIB_MINGW
 
50
/* Non Unix OSes distinguish between text and binary files.
 
51
   Set text mode on fd. Does nothing in Unix. Returns negative number on
 
52
   failure. */
 
53
int
 
54
sg_set_text_mode(int fd)
 
55
{
 
56
    return setmode(fd, O_TEXT);
 
57
}
 
58
 
 
59
/* Set binary mode on fd. Does nothing in Unix. Returns negative number on
 
60
   failure. */
 
61
int
 
62
sg_set_binary_mode(int fd)
 
63
{
 
64
    return setmode(fd, O_BINARY);
 
65
}
 
66
 
 
67
#else
 
68
/* For Unix the following functions are dummies. */
 
69
int
 
70
sg_set_text_mode(int fd)
 
71
{
 
72
    return fd;  /* fd should be >= 0 */
 
73
}
 
74
 
 
75
int
 
76
sg_set_binary_mode(int fd)
 
77
{
 
78
    return fd;
 
79
}
 
80
#endif
 
81
 
 
82
 
49
83
static void
50
84
dStrHex(const char* str, int len, long start)
51
85
{
176
210
    int num = 8192;
177
211
    long start = 0;
178
212
    int res, k, u;
179
 
    int inFile = 0;     /* stdin */
 
213
    int inFile = STDIN_FILENO;
180
214
    int doHelp = 0;
181
215
    int doHex = 0;
182
216
    int hasFilename = 0;
227
261
                fprintf(stderr, "Couldn't open file: %s\n", argv[k]);
228
262
                ret = 1;
229
263
            } else {
 
264
                sg_set_binary_mode(inFile);
230
265
                start = 0;
231
266
                printf("%shex dump of file: %s\n",
232
267
                       (doHex ? "" : "ASCII "), argv[k]);
242
277
            printf("\n");
243
278
        }
244
279
    } else {
 
280
        sg_set_binary_mode(inFile);
245
281
        while ((res = read(inFile, buff, num)) > 0) {
246
282
            if (doHex)
247
283
                dStrHexOnly(buff, res, start);