source: psi/trunk/qcm/dnotify.qcm@ 14

Last change on this file since 14 was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 1.8 KB
Line 
1/*
2-----BEGIN QCMOD-----
3name: Linux Directory Notification
4-----END QCMOD-----
5*/
6
7#include<unistd.h>
8#include<fcntl.h>
9#include<signal.h>
10#include<sys/utsname.h>
11
12//----------------------------------------------------------------------------
13// qc_dnotify
14//----------------------------------------------------------------------------
15class qc_dnotify : public ConfObj
16{
17public:
18 qc_dnotify(Conf *c) : ConfObj(c)
19 {
20 }
21
22 ~qc_dnotify()
23 {
24 remove("ftest.c");
25 remove("ftest.o");
26 }
27
28 QString name() const { return "Linux Directory Notification"; }
29 QString shortname() const { return "dnotify"; }
30
31 bool do_write()
32 {
33 char *fdata =
34 "#define _GNU_SOURCE\n"
35 "#include<unistd.h>\n"
36 "#include<fcntl.h>\n"
37 "#include<signal.h>\n"
38 "#include<sys/utsname.h>\n"
39 "\n"
40 "int main()\n"
41 "{\n"
42 " DN_DELETE|DN_CREATE|DN_RENAME|DN_MULTISHOT|DN_MODIFY|DN_ATTRIB;\n"
43 " return 0;\n"
44 "}\n";
45
46 FILE *f;
47 f = fopen("ftest.c", "w");
48 if(!f)
49 return false;
50 fwrite(fdata, strlen(fdata), 1, f);
51 fclose(f);
52
53 return true;
54 }
55
56 bool do_compile()
57 {
58 QString str = conf->qvar("QMAKE_CC") + " -c ftest.c -o ftest.o";
59 int r = conf->doCommand(str);
60 if(r == 0)
61 return true;
62 else
63 return false;
64 }
65
66 bool exec()
67 {
68 // taken from KDE
69 bool supports_dnotify = true; // not guilty until proven guilty
70 struct utsname uts;
71 int major, minor, patch;
72 if(uname(&uts) < 0)
73 supports_dnotify = false; // *shrug*
74 else if(sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
75 supports_dnotify = false; // *shrug*
76 else if( major * 1000000 + minor * 1000 + patch < 2004019 ) // <2.4.19
77 supports_dnotify = false;
78 if(!supports_dnotify)
79 return false;
80
81 if(!do_write())
82 return false;
83 if(!do_compile())
84 return false;
85
86 conf->addDefine("HAVE_DNOTIFY");
87 return true;
88 }
89};
Note: See TracBrowser for help on using the repository browser.