XRootD
Loading...
Searching...
No Matches
XrdCrc32c.cc File Reference
#include <iostream>
#include <fcntl.h>
#include <cstdio>
#include <unistd.h>
#include <sys/stat.h>
#include <cstring>
#include <sys/types.h>
#include <sys/uio.h>
#include "XrdOuc/XrdOucCRC.hh"
#include "XrdSys/XrdSysE2T.hh"
+ Include dependency graph for XrdCrc32c.cc:

Go to the source code of this file.

Macros

#define O_DIRECT   0
 

Functions

void Fatal (const char *op, const char *target)
 
int main (int argc, char *argv[])
 
void Usage (int rc)
 

Macro Definition Documentation

◆ O_DIRECT

#define O_DIRECT   0

Definition at line 51 of file XrdCrc32c.cc.

Referenced by main(), XrdPssFile::Open(), XrdOfsFile::open(), and XrdFfsWcache_create().

Function Documentation

◆ Fatal()

void Fatal ( const char * op,
const char * target )

Definition at line 58 of file XrdCrc32c.cc.

59{
60
61// Generate the message
62//
63 std::cerr <<"xrdcrc32c: Unable to "<<op<<' '<<target<<"; "<<XrdSysE2T(errno)<<std::endl;
64 exit(3);
65}
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104

References XrdSysE2T().

Referenced by XrdSecProtocolztn::XrdSecProtocolztn(), XrdSecProtocolkrb5::Authenticate(), XrdSecProtocolztn::Authenticate(), XrdSecProtocolkrb5::getCredentials(), XrdSecProtocolztn::getCredentials(), XrdSecProtocolkrb5::Init(), main(), XrdTlsContext::SetContextCiphers(), XrdSecProtocolztnInit(), and XrdSecProtocolztnObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 91 of file XrdCrc32c.cc.

92{
93// extern char *optarg;
94 extern int optind, opterr, optopt;
95 static const int buffSZ = 1024*1024;
96 const char *fPath, *fmt = "%08x";
97 int bytes, fd, opts = O_RDONLY;
98 uint32_t csVal = 0;
99 bool addPath = true, addNL = true;
100 char csBuff[16], c;
101
102// Process the options
103//
104 opterr = 0;
105 if (argc > 1 && '-' == *argv[1])
106 while ((c = getopt(argc,argv,"dhnsx")) && ((unsigned char)c != 0xff))
107 { switch(c)
108 {
109 case 'd': opts |= O_DIRECT;
110 break;
111 case 'h': Usage(0);
112 break;
113 case 'n': addNL = false;
114 break;
115 case 's': addPath = false;
116 break;
117 case 'x': fmt = "%x";
118 break;
119 default: std::cerr <<pgm <<'-' <<char(optopt) <<" option is invalid" <<std::endl;
120 Usage(1);
121 break;
122 }
123 }
124
125// Get the source argument
126//
127 if (optind < argc && strcmp(argv[optind], "-"))
128 {fPath = argv[optind];
129 if ((fd = open(fPath, opts)) < 0) Fatal("open", fPath);
130 } else {
131 fPath = "stdin";
132 fd = STDIN_FILENO;
133 }
134
135// Allocate a 1 megabyte page aligned buffer
136//
137 void *buffP;
138 int rc = posix_memalign(&buffP, sysconf(_SC_PAGESIZE), buffSZ);
139 if (rc) {errno = rc; Fatal("allocate buffer to read", fPath);}
140
141// Compute the checksum
142//
143 while((bytes = read(fd, buffP, buffSZ)) > 0)
144 {csVal = XrdOucCRC::Calc32C(buffP, bytes, csVal);}
145
146// Check if we ended with an error
147//
148 if (bytes < 0) Fatal("read", fPath);
149
150// Produce the result
151//
152 sprintf(csBuff, fmt, csVal);
153 std::cout <<(char *)csBuff;
154 if (addPath) std::cout << ' ' <<fPath;
155 if (addNL) std::cout << std::endl;
156
157// All done
158//
159 free(buffP);
160 return 0;
161}
void Fatal(const char *op, const char *target)
Definition XrdCrc32c.cc:58
void Usage(int rc)
Definition XrdCrc32c.cc:71
#define O_DIRECT
Definition XrdCrc32c.cc:51
int optopt
int optind
#define open
Definition XrdPosix.hh:71
#define read(a, b, c)
Definition XrdPosix.hh:77
struct myOpts opts
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
Definition XrdOucCRC.cc:190

References XrdOucCRC::Calc32C(), Fatal(), O_DIRECT, open, optind, optopt, opts, read, and Usage().

+ Here is the call graph for this function:

◆ Usage()

void Usage ( int rc)

Definition at line 71 of file XrdCrc32c.cc.

72{
73 std::cerr <<"\nUsage: xrdcrc32c [opts] [<path> | -]\n"
74 "\n<path> the path to the file whose checksum if to be computed."
75 "\n- compute checksum from data presented at standard in;"
76 "\n example: xrdcp <url> - | xrdcrc32c -\n"
77 "\nopts: -d -h -n -s -x\n"
78 "\n-d read data directly into the buffer, do not use the file cache."
79 "\n-h display usage information (arguments ignored)."
80 "\n-n do not end output with a newline character."
81 "\n-s do not include file path in output result."
82 "\n-x do not print leading zeroes in the checksum, if any."
83 <<std::endl;
84 exit(rc);
85}

Referenced by main().

+ Here is the caller graph for this function: