Attachment 'lfc-lr.cc'
Download 1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <cstdlib>
4 #include <ctime>
5 #include <iostream>
6 #include <vector>
7 #include <algorithm>
8 #include <iterator>
9
10 #include "lfc_api.h"
11 #include "serrno.h"
12
13 int main(int argc, char *argv[])
14 {
15 if (argc != 2) {
16 std::cerr << "Usage: " << argv[0] << " LFN" << std::endl;
17 return 1;
18 }
19
20 int status;
21 struct lfc_filestat stat;
22 status = lfc_stat(argv[1], &stat);
23 if (status) {
24 std::cerr << argv[0] << ": " << argv[1] << ": " << sstrerror(serrno) << std::endl;
25 return status;
26 }
27 if (stat.filemode & S_IFDIR) {
28 std::cerr << argv[0] << ": " << argv[1] << ": Is a directory" << std::endl;
29 return 1;
30 }
31
32 int entries;
33 struct lfc_filereplica *replica;
34 status = lfc_getreplica(argv[1], 0, 0, &entries, &replica);
35 if (status) {
36 std::cerr << argv[0] << ": " << argv[1] << ": " << sstrerror(serrno) << std::endl;
37 return status;
38 }
39
40 srand(std::time(0));
41 srand48(std::time(0));
42 std::vector<std::string> v(entries);
43 for (int i = 0; i < entries; i++)
44 v[i].assign(replica[i].sfn);
45 std::random_shuffle(v.begin(), v.end());
46 std::copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
47 std::free(replica);
48 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.