FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
livecode/engine/src/dsklnx.cpp at develop · livecodeali/livecode · GitHub
livecodeali
/
livecode
Public
forked from
livecode/livecode
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
livecode
/
engine
/
src
/
dsklnx.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
2230 lines (1925 loc) · 69.7 KB
Breadcrumbs
livecode
/
engine
/
src
/
dsklnx.cpp
Copy path
File metadata and controls
2230 lines (1925 loc) · 69.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>.
*/
#
include
"
lnxprefix.h
"
#
include
"
osspec.h
"
#
include
"
globdefs.h
"
#
include
"
filedefs.h
"
#
include
"
objdefs.h
"
#
include
"
parsedef.h
"
#
include
"
mcio.h
"
#
include
"
system.h
"
#
include
"
foundation.h
"
#
include
"
object.h
"
#
include
"
stack.h
"
#
include
"
card.h
"
#
include
"
mcerror.h
"
//
#include "param.h"
#
include
"
handler.h
"
#
include
"
util.h
"
#
include
"
globals.h
"
//
#include "ports.cpp"
#
include
"
socket.h
"
//
#include "mcssl.h"
//
#include "securemode.h"
#
include
"
mode.h
"
#
include
"
player.h
"
#
include
"
text.h
"
#
include
"
variable.h
"
#
include
<
sys/utsname.h
>
#
include
<
sys/ioctl.h
>
#
include
<
sys/mman.h
>
#
include
<
sys/dir.h
>
#
include
<
sys/wait.h
>
#
include
<
sys/time.h
>
#
include
<
sys/statvfs.h
>
#
include
<
dlfcn.h
>
#
include
<
termios.h
>
//
#include <langinfo.h>
#
include
<
locale.h
>
#
include
<
pwd.h
>
#
include
<
fcntl.h
>
//
SN-2014-12-17: [[ Bug 14220 ]] Server should not wait put rather poll
#
include
<
poll.h
>
#
include
<
libgnome/gnome-url.h
>
#
include
<
libgnome/gnome-program.h
>
#
include
<
libgnome/gnome-init.h
>
#
include
<
libgnomevfs/gnome-vfs.h
>
#
include
<
libgnomevfs/gnome-vfs-utils.h
>
#
include
<
libgnomevfs/gnome-vfs-mime.h
>
#
include
<
libgnomevfs/gnome-vfs-mime-handlers.h
>
#
include
<
gtk/gtk.h
>
#
include
<
syslog.h
>
//
//////////////////////////////////////////////////////////////////////////////
//
This is in here so we do not need GLIBC2.4
extern
"
C
"
void
__attribute__
((noreturn)) __stack_chk_fail (
void
)
{
abort
();
}
//
//////////////////////////////////////////////////////////////////////////////
//
MW-2005-02-22: Make global for now so opensslsocket.cpp can access it
real8 curtime;
static
Boolean alarmpending;
//
MW-2013-10-08: [[ Bug 11259 ]] We use our own tables on linux since
//
we use a fixed locale which isn't available on all systems.
#
if
!defined(_LINUX_SERVER) && !defined(_LINUX_DESKTOP)
uint1 *MClowercasingtable =
NULL
;
uint1 *MCuppercasingtable =
NULL
;
#
endif
//
//
//////////////////////////////////////////////////////////////////////////////
static
void
parseSerialControlStr
(
char
*setting,
struct
termios
*theTermios)
{
int
baud =
0
;
char
*type = setting;
char
*value =
NULL
;
if
((value =
strchr
(type,
'
=
'
)) !=
NULL
)
{
*value++ =
'
\0
'
;
if
(
MCU_strncasecmp
(type,
"
baud
"
,
strlen
(type)) ==
0
)
{
long
baudrate =
strtol
(value,
NULL
,
10
);
switch
(baudrate)
{
case
4000000
: baud =
B4000000
;
break
;
case
3500000
: baud =
B3500000
;
break
;
case
3000000
: baud =
B3000000
;
break
;
case
2500000
: baud =
B2500000
;
break
;
case
2000000
: baud =
B2000000
;
break
;
case
1500000
: baud =
B1500000
;
break
;
case
1152000
: baud =
B1152000
;
break
;
case
1000000
: baud =
B1000000
;
break
;
case
921600
: baud =
B921600
;
break
;
case
576000
: baud =
B576000
;
break
;
case
500000
: baud =
B500000
;
break
;
case
460800
: baud =
B460800
;
break
;
case
230400
: baud =
B230400
;
break
;
case
115200
: baud =
B115200
;
break
;
case
57600
: baud =
B57600
;
break
;
case
38400
: baud =
B38400
;
break
;
case
19200
: baud =
B19200
;
break
;
case
9600
: baud =
B9600
;
break
;
case
4800
: baud =
B4800
;
break
;
case
2400
: baud =
B2400
;
break
;
case
1800
: baud =
B1800
;
break
;
case
1200
: baud =
B1200
;
break
;
case
600
: baud =
B600
;
break
;
case
300
: baud =
B300
;
break
;
default
:
baud =
B9600
;
break
;
}
cfsetispeed
(theTermios, baud);
cfsetospeed
(theTermios, baud);
}
else
if
(
MCU_strncasecmp
(type,
"
parity
"
,
strlen
(type)) ==
0
)
{
if
(value[
0
] ==
'
N
'
|| value[
0
] ==
'
n
'
)
theTermios->
c_cflag
&= ~(
PARENB
|
PARODD
);
else
if
(value[
0
] ==
'
O
'
|| value[
0
] ==
'
o
'
)
theTermios->
c_cflag
|=
PARENB
|
PARODD
;
else
if
(value[
0
] ==
'
E
'
|| value[
0
] ==
'
e
'
)
theTermios->
c_cflag
|=
PARENB
;
}
else
if
(
MCU_strncasecmp
(type,
"
data
"
,
strlen
(type)) ==
0
)
{
short
data =
atoi
(value);
switch
(data)
{
case
5
:
theTermios->
c_cflag
|=
CS5
;
break
;
case
6
:
theTermios->
c_cflag
|=
CS6
;
break
;
case
7
:
theTermios->
c_cflag
|=
CS7
;
break
;
case
8
:
theTermios->
c_cflag
|=
CS8
;
break
;
}
}
else
if
(
MCU_strncasecmp
(type,
"
stop
"
,
strlen
(type)) ==
0
)
{
double
stopbit =
strtol
(value,
NULL
,
10
);
if
(stopbit ==
1.0
)
theTermios->
c_cflag
&= ~
CSTOPB
;
else
if
(stopbit ==
1.5
)
theTermios->
c_cflag
&= ~
CSTOPB
;
else
if
(stopbit ==
2.0
)
theTermios->
c_cflag
|=
CSTOPB
;
}
}
}
static
void
configureSerialPort
(
int
sRefNum
)
{
/*
***************************************************************************
*parse MCserialcontrolstring and set the serial output port to the settings*
*defined by MCserialcontrolstring accordingly *
***************************************************************************
*/
//
initialize to the default setting
struct
termios
theTermios;
if
(
tcgetattr
(
sRefNum
, &theTermios) <
0
)
{
MCLog
(
"
Error getting terminous attributes
"
);
}
cfsetispeed
(&theTermios,
B9600
);
theTermios.
c_cflag
=
CS8
;
MCAutoStringRefAsSysString t_serial_settings;
/*
UNCHECKED
*/
t_serial_settings.
Lock
(MCserialcontrolsettings);
char
*controlptr =
strclone
(*t_serial_settings);
char
*str = controlptr;
char
*each =
NULL
;
while
((each =
strchr
(str,
'
'
)) !=
NULL
)
{
*each =
'
\0
'
;
each++;
parseSerialControlStr
(str, &theTermios);
str = each;
}
//
configure the serial output device
parseSerialControlStr
(str,&theTermios);
if
(
tcsetattr
(
sRefNum
,
TCSANOW
, &theTermios) <
0
)
{
MCLog
(
"
Error setting terminous attributes
"
);
}
delete[]
controlptr;
return
;
}
//
//////////////////////////////////////////////////////////////////////////////
static
IO_stat
MCS_lnx_shellread
(
int
fd,
char
*&buffer, uint4 &buffersize, uint4 &size)
{
MCshellfd = fd;
size =
0
;
while
(True)
{
int
readsize =
0
;
ioctl
(fd,
FIONREAD
, (
char
*)&readsize);
readsize +=
READ_PIPE_SIZE
;
if
(size + readsize > buffersize)
{
if
(!
MCMemoryResizeArray
(buffersize + readsize +
1
,
buffer, buffersize))
return
IO_ERROR
;
}
errno =
0
;
int4 amount =
read
(fd, &buffer[size], readsize);
if
(amount <=
0
)
{
if
(errno !=
EAGAIN
&& errno !=
EWOULDBLOCK
&& errno !=
EINTR
)
break
;
MCU_play
();
//
SN-2014-12-17: [[ Bug 14220 ]] The server wasn't waiting pre-7.0
#
ifdef
_SERVER
pollfd t_poll_fd;
t_poll_fd . fd = fd;
t_poll_fd . events =
POLLIN
;
t_poll_fd . revents =
0
;
//
SN-2015-02-12: [[ Bug 14441 ]] poll might as well get signal interrupted
//
and we don't want to miss the reading for that only reason.
int
t_result;
do
{
t_result =
poll
(&t_poll_fd,
1
, -
1
);
}
while
(t_result !=
1
||
(errno !=
EAGAIN
&& errno !=
EINTR
&& errno !=
EWOULDBLOCK
));
//
SN-2015-02-26: [[ CID 37859 ]] Dead code removed (t_result is
//
always different from -1 here
#
else
if
(MCscreen->
wait
(
READ_INTERVAL
, False, True))
{
MCshellfd = -
1
;
return
IO_ERROR
;
}
#
endif
}
else
size += amount;
}
MCshellfd = -
1
;
return
IO_NORMAL
;
}
//
//////////////////////////////////////////////////////////////////////////////
static
Boolean
MCS_lnx_nodelay
(int4 fd)
{
return
fcntl
(fd,
F_SETFL
, (
fcntl
(fd,
F_GETFL
,
0
) &
O_APPEND
) |
O_NONBLOCK
)
>=
0
;
}
//
//////////////////////////////////////////////////////////////////////////////
bool
MCS_lnx_is_link
(MCStringRef p_path)
{
MCAutoStringRefAsSysString t_path;
/*
UNCHECKED
*/
t_path.
Lock
(p_path);
struct
stat64
buf;
return
(
lstat64
(*t_path, &buf) ==
0
&&
S_ISLNK
(buf.
st_mode
));
}
bool
MCS_lnx_readlink
(MCStringRef p_path, MCStringRef& r_link)
{
struct
stat64
t_stat;
ssize_t
t_size;
MCAutoArray<
char
> t_buffer;
MCAutoStringRefAsSysString t_path;
/*
UNCHECKED
*/
t_path.
Lock
(p_path);
if
(
lstat64
(*t_path, &t_stat) == -
1
||
//
SN-2014-09-02: [[ Bug 13323 ]] The size needs be 1 bigger to allow
//
a final NIL-byte.
!t_buffer.
New
(t_stat.
st_size
+
1
))
return
false
;
t_size =
readlink
(*t_path, (
char
*)t_buffer.
Ptr
(), t_stat.
st_size
);
if
(t_size != t_stat.
st_size
)
return
false
;
return
MCStringCreateWithSysString
(t_buffer.
Ptr
(), r_link);
}
//
//////////////////////////////////////////////////////////////////////////////
//
REFACTORED FROM lnxmisc.cpp
#
include
<
iconv.h
>
struct
ConverterRecord
{
ConverterRecord *next;
const
char
*encoding;
iconv_t
converter;
};
static
iconv_t
fetch_converter
(
const
char
*p_encoding)
{
static
ConverterRecord *s_records =
NULL
;
ConverterRecord *t_previous, *t_current;
for
(t_previous =
NULL
, t_current = s_records; t_current !=
NULL
; t_previous = t_current, t_current = t_current -> next)
if
(t_current -> encoding == p_encoding)
break
;
if
(t_current ==
NULL
)
{
//
SN-2015-11-19: [[ Bug 16450 ]] Ask for UTF-16LE to avoid iconv to put
//
a BOM char at the start of the stream
iconv_t
t_converter;
t_converter =
iconv_open
(
"
UTF-16LE
"
, p_encoding);
ConverterRecord *t_record;
t_record =
new
(nothrow) ConverterRecord;
t_record -> next = s_records;
t_record -> encoding = p_encoding;
t_record -> converter = t_converter;
s_records = t_record;
return
t_record -> converter;
}
if
(t_previous !=
NULL
)
{
t_previous -> next = t_current -> next;
t_current -> next = s_records;
s_records = t_current;
}
return
s_records -> converter;
}
//
//////////////////////////////////////////////////////////////////////////////
#
define
DNS_SCRIPT
"
repeat for each line l in url
\"
binfile:/etc/resolv.conf
\"
;\
if word 1 of l is
\"
nameserver
\"
then put word 2 of l & cr after it; end repeat;\
delete last char of it; return it
"
#
define
LAUNCH_URL_SCRIPT
"
put
\"
%@
\"
into tFilename;
"
\
"
put empty into tCmd;
"
\
"
if tCmd is empty and shell(
\"
which xdg-open
\"
) is not empty then;
"
\
"
put
\"
xdg-open
\"
into tCmd;
"
\
"
end if;
"
\
"
if tCmd is empty and $GNOME_DESKTOP_SESSION_ID is not empty and shell(
\"
which gnome-open
\"
) is not empty then;
"
\
"
put
\"
gnome-open
\"
into tCmd;
"
\
"
end if;
"
\
"
if tCmd is empty and $KDE_FULL_SESSION is not empty then;
"
\
"
if shell(
\"
which kde-open
\"
) is not empty then;
"
\
"
put
\"
kde-open
\"
into tCmd;
"
\
"
else if shell(
\"
which kfmclient
\"
) is not empty then;
"
\
"
put
\"
kfmclient exec
\"
into tCmd;
"
\
"
end if;
"
\
"
end if;
"
\
"
if tCmd is not empty then;
"
\
"
launch tFilename with tCmd;
"
\
"
else;
"
\
"
return
\"
not supported
\"
;
"
\
"
end if;
"
//
//////////////////////////////////////////////////////////////////////////////
#
ifdef
NOATON
int
inet_aton
(
const
char
*cp,
struct
in_addr
*inp)
{
unsigned
long
rv =
inet_addr
(cp);
//
fprintf(stderr, "%d\n", rv);
if
(rv == -
1
)
return
False;
memcpy
(inp, &rv,
sizeof
(
unsigned
long
));
return
True;
}
#
endif
//
TS-2008-03-03 : Make this global so that MCS_checkprocesses () can look at it
//
and figure out if one of its children have already been waited on in the
//
SIGCHLD handler.
pid_t
waitedpid;
static
void
handle_signal
(
int
sig)
{
MCHandler
handler
(
HT_MESSAGE
);
switch
(sig)
{
case
SIGUSR1
:
MCsiguser1++;
break
;
case
SIGUSR2
:
MCsiguser2++;
break
;
case
SIGTERM
:
switch
(MCdefaultstackptr->
getcard
()->
message
(MCM_shut_down_request))
{
case
ES_NORMAL
:
return
;
case
ES_NOT_HANDLED
:
if
(handler.
getpass
())
{
MCdefaultstackptr->
getcard
()->
message
(MCM_shut_down);
MCquit = True;
//
set MC quit flag, to invoke quitting
return
;
}
default
:
break
;
}
case
SIGILL
:
case
SIGBUS
:
case
SIGSEGV
:
{
MCAutoStringRefAsSysString t_cmd;
/*
UNCHECKED
*/
t_cmd.
Lock
(MCcmd);
fprintf
(stderr,
"
%s exiting on signal %d
\n
"
, *t_cmd, sig);
MCS_killall
();
exit
(-
1
);
}
case
SIGHUP
:
case
SIGINT
:
case
SIGQUIT
:
case
SIGIOT
:
fprintf
(stderr,
"
\n\n
Got SIGIOT
\n
"
);
if
(MCnoui)
exit
(
1
);
MCabortscript = True;
break
;
case
SIGFPE
:
errno =
EDOM
;
break
;
case
SIGCHLD
:
{
#
if
defined(_LINUX_DESKTOP)
MCPlayerHandle t_player = MCplayers;
//
If we have some players waiting then deal with these first
waitedpid = -
1
;
if
(t_player.
IsValid
())
{
waitedpid =
wait
(
NULL
);
//
Moving these two lines half fixes bug 5966 - however it still isn't quite right
//
as there will still be some interaction between a player and shell command
while
(t_player.
IsValid
())
{
if
(t_player.
IsValid
() && waitedpid == t_player->
getpid
())
{
if
(t_player->
isdisposable
())
t_player->
playstop
();
else
MCscreen->
delaymessage
(t_player, MCM_play_stopped,
NULL
,
NULL
);
t_player->
shutdown
();
break
;
}
t_player = t_player ->
getnextplayer
() ;
}
}
else
{
//
Check to see if we have created a video window. If we have got to here it means
//
that we could not start mplayer -- so the child thread has exited, but the player
//
object has not had a chance to be created yet. TODO - investigate if there is a
//
cleaner way of dealing with this situation.
if
( MClastvideowindow !=
DNULL
)
{
gdk_window_hide
(MClastvideowindow);
gdk_window_destroy
(MClastvideowindow);
MClastvideowindow =
DNULL
;
}
else
{
MCS_checkprocesses
();
}
}
#
endif
/*
LINUX_DESKTOP
*/
}
break
;
case
SIGALRM
:
MCalarm = True;
#
ifdef
NOITIMERS
alarm
(
1
);
#
endif
break
;
case
SIGPIPE
:
default
:
break
;
}
return
;
}
//
//////////////////////////////////////////////////////////////////////////////
class
MCStdioFileHandle
:
public
MCSystemFileHandle
{
public:
MCStdioFileHandle
(
FILE
* p_fptr)
{
m_fptr = p_fptr;
m_is_eof =
false
;
}
virtual
void
Close
(
void
)
{
if
(m_fptr !=
NULL
)
fclose
(m_fptr);
delete
this
;
}
//
Returns true if an attempt has been made to read past the end of the
//
stream.
virtual
bool
IsExhausted
(
void
)
{
return
feof
(m_fptr);
}
virtual
bool
Read
(
void
*p_buffer,
uint32_t
p_length,
uint32_t
& r_read)
{
if
(MCabortscript || p_buffer ==
NULL
)
return
false
;
char
*sptr = (
char
*)p_buffer;
uint4 nread;
uint4 toread = p_length;
uint4 offset =
0
;
errno =
0
;
while
((nread =
fread
(&sptr[offset],
1
, toread, m_fptr)) != toread)
{
offset += nread;
r_read = offset;
if
(
ferror
(m_fptr))
{
clearerr
(m_fptr);
if
(errno ==
EAGAIN
)
return
true
;
if
(errno ==
EINTR
)
{
toread -= nread;
continue
;
}
}
return
false
;
}
r_read = offset + nread;
return
true
;
}
virtual
bool
Write
(
const
void
*p_buffer,
uint32_t
p_length)
{
if
(
fwrite
(p_buffer,
1
, p_length, m_fptr) != p_length)
return
false
;
return
true
;
}
virtual
bool
Seek
(
int64_t
p_offset,
int
p_dir)
{
return
fseeko64
(m_fptr, p_offset, p_dir >
0
?
SEEK_SET
: (p_dir <
0
?
SEEK_END
:
SEEK_CUR
)) ==
0
;
}
virtual
bool
Truncate
(
void
)
{
return
ftruncate
(
fileno
(m_fptr),
ftell
(m_fptr)) ==
0
;
}
virtual
bool
Sync
(
void
)
{
if
(m_fptr !=
NULL
)
{
int64_t
pos =
ftello64
(m_fptr);
if
(
fseeko64
(m_fptr, pos,
SEEK_SET
) !=
0
)
return
false
;
}
return
true
;
}
virtual
bool
Flush
(
void
)
{
if
(
fflush
(m_fptr))
return
false
;
return
true
;
}
virtual
bool
PutBack
(
char
p_char)
{
if
(
ungetc
(p_char, m_fptr) != p_char)
return
false
;
return
true
;
}
virtual
int64_t
Tell
(
void
)
{
return
ftello64
(m_fptr);
}
virtual
void
*
GetFilePointer
(
void
)
{
return
(
void
*)m_fptr;
}
virtual
uint64_t
GetFileSize
(
void
)
{
struct
stat64
buf;
int
fd =
fileno
(m_fptr);
if
(
fstat64
(fd, &buf))
return
0
;
return
buf.
st_size
;
}
virtual
bool
TakeBuffer
(
void
*& r_buffer,
size_t
& r_length)
{
return
false
;
}
virtual
FILE
*
GetStream
(
void
)
{
return
m_fptr;
}
private:
FILE
*m_fptr;
bool
m_is_eof;
};
//
//////////////////////////////////////////////////////////////////////////////
class
MCLinuxDesktop
:
public
MCSystemInterface
{
public:
virtual
MCServiceInterface *
QueryService
(MCServiceType type)
{
//
No Linux-specific services
return
nil;
}
virtual
bool
Initialize
(
void
)
{
IO_stdin = MCsystem ->
OpenFd
(
0
,
kMCOpenFileModeRead
);
IO_stdout = MCsystem ->
OpenFd
(
1
,
kMCOpenFileModeWrite
);
IO_stderr = MCsystem ->
OpenFd
(
2
,
kMCOpenFileModeWrite
);
//
Internally, LiveCode assumes sorting orders etc are those of en_US.
//
Additionally, the "native" string encoding for Linux is ISO-8859-1
//
(even if the Linux system is using something different).
const
char
*t_internal_locale =
"
en_US.ISO-8859-1
"
;
setlocale
(
LC_CTYPE
, t_internal_locale);
setlocale
(
LC_COLLATE
, t_internal_locale);
MCinfinity =
HUGE_VAL
;
struct
sigaction
action;
memset
((
char
*)&action,
0
,
sizeof
(action));
action.
sa_handler
= handle_signal;
action.
sa_flags
=
SA_RESTART
;
action.
sa_flags
|=
SA_NOCLDSTOP
;
sigaction
(
SIGCHLD
, &action,
NULL
);
sigaction
(
SIGALRM
, &action,
NULL
);
#
ifndef
_DEBUG
sigaction
(
SIGHUP
, &action,
NULL
);
sigaction
(
SIGINT
, &action,
NULL
);
sigaction
(
SIGQUIT
, &action,
NULL
);
sigaction
(
SIGILL
, &action,
NULL
);
sigaction
(
SIGIOT
, &action,
NULL
);
sigaction
(
SIGFPE
, &action,
NULL
);
sigaction
(
SIGBUS
, &action,
NULL
);
sigaction
(
SIGSEGV
, &action,
NULL
);
sigaction
(
SIGPIPE
, &action,
NULL
);
sigaction
(
SIGTERM
, &action,
NULL
);
sigaction
(
SIGUSR1
, &action,
NULL
);
sigaction
(
SIGUSR2
, &action,
NULL
);
#
ifndef
_LINUX
sigaction
(
SIGSYS
, &action,
NULL
);
#
endif
#
endif
#
ifndef
_SERVER
//
ST-2015-04-20: [[ Bug 15257 ]] Stdin shouldn't be set to
//
non-blocking in server.
if
(!
IsInteractiveConsole
(
0
))
MCS_lnx_nodelay
(
0
);
#
endif
//
MW-2013-10-01: [[ Bug 11160 ]] At the moment NBSP is not considered a space.
MCctypetable[
160
] &= ~(
1
<<
4
);
MCValueAssign
(MCshellcmd,
MCSTR
(
"
/bin/sh
"
));
return
true
;
}
virtual
void
Finalize
(
void
)
{
}
virtual
void
Debug
(MCStringRef p_string)
{
MCAutoStringRefAsSysString t_string;
if
(t_string.
Lock
(p_string))
syslog
(
LOG_DEBUG
,
"
%s
"
, *t_string);
}
virtual
real64_t
GetCurrentTime
(
void
)
{
struct
timezone
tz;
struct
timeval
tv;
gettimeofday
(&tv, &tz);
curtime = tv.
tv_sec
+ (real8)tv.
tv_usec
/
1000000.0
;
return
curtime;
}
virtual
bool
GetVersion
(MCStringRef& r_string)
{
struct
utsname
u;
uname
(&u);
MCAutoStringRef t_sysname, t_release;
/*
UNCHECKED
*/
MCStringCreateWithSysString
(u.
sysname
, &t_sysname);
/*
UNCHECKED
*/
MCStringCreateWithSysString
(u.
release
, &t_release);
return
MCStringFormat
(r_string,
"
%@ %@
"
, *t_sysname, *t_release);
}
virtual
bool
GetMachine
(MCStringRef& r_string)
{
struct
utsname
u;
uname
(&u);
return
MCStringCreateWithNativeChars
((
const
char_t
*)u.
machine
,
MCCStringLength
(u.
machine
), r_string);
}
virtual
bool
GetAddress
(MCStringRef& r_address)
{
struct
utsname
u;
uname
(&u);
MCAutoStringRef t_nodename;
/*
UNCHECKED
*/
MCStringCreateWithSysString
(u.
nodename
, &t_nodename);
return
MCStringFormat
(r_address,
"
%@:%@
"
, *t_nodename, MCcmd);
}
virtual
uint32_t
GetProcessId
(
void
)
{
return
getpid
();
}
virtual
void
Alarm
(
real64_t
p_when)
{
if
(!MCnoui)
{
#
ifdef
NOITIMERS
if
(p_when !=
0
.)
alarm
(p_when +
1.0
);
else
alarm
(
0
);
#
else
static
real8 oldsecs;
if
(p_when != oldsecs)
{
itimerval val;
val.
it_interval
.
tv_sec
= (
long
)p_when;
val.
it_interval
.
tv_usec
= (
long
)((p_when - (
double
)(
long
)p_when) *
1000000.0
);
val.
it_value
= val.
it_interval
;
setitimer
(
ITIMER_REAL
, &val,
NULL
);
oldsecs = p_when;
}
#
endif
if
(p_when ==
0.0
)
alarmpending = False;
else
alarmpending = True;
}
}
virtual
void
Sleep
(
real64_t
p_when)
{
Boolean wasalarm = alarmpending;
if
(alarmpending)
MCS_alarm
(
0.0
);
struct
timeval
timeoutval;
timeoutval.
tv_sec
= (
long
)p_when;
timeoutval.
tv_usec
= (
long
)((p_when -
floor
(p_when)) *
1000000.0
);
select
(
0
,
NULL
,
NULL
,
NULL
, &timeoutval);
if
(wasalarm)
MCS_alarm
(
CHECK_INTERVAL
);
}
virtual
void
SetEnv
(MCStringRef p_name, MCStringRef p_value)
{
#
ifdef
NOSETENV
char
*dptr =
new
(nothrow)
char
[
strlen
(p_name) +
strlen
(p_value) +
2
];
sprintf
(dptr,
"
%s=%s
"
, p_name, p_value);
putenv
(dptr);
#
else
MCAutoStringRefAsSysString t_name, t_value;
/*
UNCHECKED
*/
t_name.
Lock
(p_name);
if
(p_value == nil)
unsetenv
(*t_name);
else
{
/*
UNCHECKED
*/
t_value.
Lock
(p_value);
setenv
(*t_name, *t_value, True);
}
#
endif
}
virtual
bool
GetEnv
(MCStringRef p_name, MCStringRef& r_value)
{
MCAutoStringRefAsSysString t_name;
/*
UNCHECKED
*/
t_name.
Lock
(p_name);
char
*t_env_value =
getenv
(*t_name);
//
We need to know whethere we actually got an environment variable
//
or if it defaulted to an empty stringref because the env variable
//
was unset
return
t_env_value != nil &&
MCStringCreateWithSysString
(t_env_value, r_value);
}
virtual
Boolean
CreateFolder
(MCStringRef p_path)
{
MCAutoStringRefAsSysString t_path;
MCAutoStringRef t_resolved_path_string;
if
(
MCS_resolvepath
(p_path, &t_resolved_path_string))
{
/*
UNCHECKED
*/
t_path.
Lock
(*t_resolved_path_string);
return
mkdir
(*t_path,
0777
) ==
0
;
}
return
false
;
}
virtual
Boolean
DeleteFolder
(MCStringRef p_path)
{
MCAutoStringRefAsSysString t_path;
MCAutoStringRef t_resolved_path_string;
if
(
MCS_resolvepath
(p_path, &t_resolved_path_string))
{
/*
UNCHECKED
*/
t_path.
Lock
(*t_resolved_path_string);
return
rmdir
(*t_path) ==
0
;
}
return
false
;
}
virtual
Boolean
DeleteFile
(MCStringRef p_path)
{
MCAutoStringRefAsSysString t_path;
MCAutoStringRef t_resolved_path;
MCS_resolvepath
(p_path, &t_resolved_path);
/*
UNCHECKED
*/
t_path.
Lock
(*t_resolved_path);
Boolean done =
unlink
(*t_path) ==
0
;
return
done;
}
virtual
Boolean
RenameFileOrFolder
(MCStringRef p_old_name, MCStringRef p_new_name)
{
MCAutoStringRef t_old_resolved_path, t_new_resolved_path;
MCS_resolvepath
(p_old_name, &t_old_resolved_path);
MCS_resolvepath
(p_new_name, &t_new_resolved_path);
Boolean done;
#
ifndef
NORENAME
MCAutoStringRefAsSysString t_from, t_to;
/*
UNCHECKED
*/
t_from.
Lock
(*t_old_resolved_path);
/*
UNCHECKED
*/
t_to.
Lock
(*t_new_resolved_path);
done =
rename
(*t_from, *t_to) ==
0
;
#
else
//
doesn't work on directories
MCAutoStringRefAsSysString t_from, t_to;
/*
UNCHECKED
*/
t_from.
Lock
(*t_old_resovled_path);
/*
UNCHECKED
*/
t_to.
Lock
(*t_new_resolved_path);
done = True;
if
(
link
(*t_from, *t_to) !=
0
)
done = False;
else
if
(
unlink
(*t_from) !=
0
)
{
unlink
(*t_to);
done = False;
}
#
endif
return
done;
}
virtual
Boolean
BackupFile
(MCStringRef p_old_name, MCStringRef p_new_name)
{
return
MCS_rename
(p_old_name, p_new_name);
}
virtual
Boolean
UnbackupFile
(MCStringRef p_old_name, MCStringRef p_new_name)
{
return
MCS_rename
(p_old_name, p_new_name);
}
virtual
Boolean
CreateAlias
(MCStringRef p_target, MCStringRef p_alias)
{
MCAutoStringRef t_target;
MCAutoStringRef t_alias;
/*
UNCHECKED
*/
MCS_resolvepath
(p_target, &t_target);
/*
UNCHECKED
*/
MCS_resolvepath
(p_alias, &t_alias);
MCAutoStringRefAsSysString t_target_sys, t_alias_sys;
/*
UNCHECKED
*/
t_target_sys.
Lock
(*t_target);
/*
UNCHECKED
*/
t_alias_sys.
Lock
(*t_alias);
return
symlink
(*t_target_sys, *t_alias_sys) ==
0
;
}
//
NOTE: 'ResolveAlias' returns a standard (not native) path.
virtual
Boolean
ResolveAlias
(MCStringRef p_target, MCStringRef& r_dest)
{
return
MCS_resolvepath
(p_target, r_dest);
}
virtual
bool
GetCurrentFolder
(MCStringRef& r_path)
{
MCAutoArray<
char
> t_buffer;
if
(!t_buffer.
New
(
PATH_MAX
+
1
))
return
false
;
if
(
NULL
==
getcwd
((
char
*)t_buffer.
Ptr
(),
PATH_MAX
+
1
))
return
false
;
return
MCStringCreateWithSysString
(t_buffer.
Ptr
(), r_path);
}
//
/* LEGACY */ char *GetCurrentFolder(void);
virtual
Boolean
SetCurrentFolder
(MCStringRef p_path)
{
MCAutoStringRef t_new_path;
if
(
MCS_resolvepath
(p_path, &t_new_path))
{
MCAutoStringRefAsSysString t_path_sys;
/*
UNCHECKED
*/
t_path_sys.
Lock
(*t_new_path);
return
chdir
(*t_path_sys) ==
0
;
}
return
false
;
}
//
NOTE: 'GetStandardFolder' returns a standard (not native) path.
virtual
Boolean
GetStandardFolder
(MCNameRef p_type, MCStringRef& r_folder)
{
MCAutoStringRef t_home, t_tilde;
if
(!
MCStringCreateWithCString
(
"
~
"
, &t_tilde) ||
!
MCS_resolvepath
(*t_tilde, &t_home))
return
false
;
if
(
MCNameIsEqualToCaseless
(p_type, MCN_desktop))
return
MCStringFormat
(r_folder,
"
%@/Desktop
"
, *t_home);
else
if
(
MCNameIsEqualToCaseless
(p_type, MCN_home))
return
MCStringCopy
(*t_home, r_folder);
else
if
(
MCNameIsEqualToCaseless
(p_type, MCN_temporary))
return
MCStringCreateWithCString
(
"
/tmp
"
, r_folder);
//
SN-2014-08-08: [[ Bug 13026 ]] Fix ported from 6.7
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL