summaryrefslogtreecommitdiffstats
path: root/audio/sound-juicer/files/patch-src::sj-util.c
blob: ac2bcfbd80a6c0064700c906bb07d155723425b4 (plain) (blame)
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
--- src/sj-util.c.orig  Wed Jan  7 20:38:00 2004
+++ src/sj-util.c   Fri Jan 23 10:48:36 2004
@@ -120,6 +120,9 @@
     gtk_widget_destroy (dialog);
     goto done;
   }
+#ifdef __FreeBSD__
+  ioctl (fd, CDIOCALLOW);
+#endif
   result = ioctl (fd, CDROMEJECT);
   if (result == -1) {
     GtkWidget *dialog;
@@ -148,21 +151,33 @@
 tray_is_opened (const char *device)
 {
   int fd, status;
-  
+
+#if defined(__linux__)
   fd = open (device, O_RDONLY | O_NONBLOCK | O_EXCL);
   if (fd < 0) {
     return FALSE;
   }
-  
+
   status = ioctl (fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
+  close (fd);
   if (status < 0) {
-    close (fd);
     return FALSE;
   }
   
-  close (fd);
-  
   return status == CDS_TRAY_OPEN;
+#elif defined(__FreeBSD__)
+  struct ioc_toc_header h;
+
+  fd = open (device, O_RDONLY | O_NONBLOCK | O_EXCL);
+  if (fd < 0) {
+    return FALSE;
+  }
+
+  status = ioctl (fd, CDIOREADTOCHEADER, &h);
+  close (fd);
+
+  return status < 0;
+#endif
 }
 
 gboolean is_audio_cd (const char *device)
@@ -170,6 +185,10 @@
   CDMediaType type;
   int fd, status;
 
+  if (tray_is_opened (device)) {
+    return FALSE;
+  }
+
   type = guess_media_type (device);
   switch (type) {
     case CD_MEDIA_TYPE_CD:
@@ -189,15 +208,18 @@
     return FALSE;
   }
 
+#if defined(__linux__)
   status = ioctl (fd, CDROM_DISC_STATUS, CDSL_CURRENT);
+  close (fd);
   if (status < 0) {
-    close (fd);
     return FALSE;
   }
-
-  close (fd);
-
   return status == CDS_AUDIO;
+#elif defined (__FreeBSD__)
+  return TRUE;
+#else
+  return TRUE;
+#endif
 }
 
 /* Pass NULL to use g_free */