dtexec,DtSvc/MsgLog.c: coverity CID 89585; resource leak
[oweals/cde.git] / cde / lib / DtXinerama / DtXinerama.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2013, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * Jon Trulson, Xi Graphics 4/11/2001
25  *
26  * $XiGId: DtXinerama.c,v 1.1 2001/04/12 03:01:14 jon Exp $
27  *
28  * A Xinerama wrapper for CDE
29  *
30  */
31
32 #include <stdio.h>
33 #include <unistd.h>
34 #include <stdlib.h>
35 #include <X11/Xlib.h>
36
37 #include "DtXinerama.h"
38
39 /* return a DtXineramaInfo_t (or NULL if no Xinerama) available */
40
41 DtXineramaInfo_t *_DtXineramaInit(Display *dpy)
42 {
43   DtXineramaInfo_t *tmpDtXI = NULL;
44   XineramaScreenInfo *XinerScrnInfo = NULL;
45   int number = 0;
46
47   if (!dpy)
48     return(NULL);
49
50   XinerScrnInfo = XineramaQueryScreens(dpy, &number);
51
52   if (number <= 0 || XinerScrnInfo == NULL) /* then we don't have it */
53     return(NULL);
54
55                                 /* allocate some space for it */
56   if ((tmpDtXI = (DtXineramaInfo_t *)malloc(sizeof(DtXineramaInfo_t))) == NULL)
57     {                           /* malloc failure */
58 #ifdef DEBUG
59       fprintf(stderr, "_DtXineramaInit: malloc failed\n");
60 #endif
61       
62       free(XinerScrnInfo);
63       return(NULL);
64     }
65
66   tmpDtXI->numscreens = number;
67   tmpDtXI->ScreenInfo = XinerScrnInfo;
68
69   return(tmpDtXI);
70 }
71
72
73 /* Return w, h, xorg, and yorg for the specified screen.  Return True */
74 /* if a valid screen, False otherwise */
75 Bool _DtXineramaGetScreen(DtXineramaInfo_t *DtXI, unsigned int screen,
76                           unsigned int *w, unsigned int *h, 
77                           unsigned int *xorg, unsigned int *yorg)
78 {
79
80   if (DtXI == NULL)
81     return(False);
82
83   if (DtXI->numscreens == 0)
84     return(False);              /* no screens or no Xinerama */
85
86   if (screen >= DtXI->numscreens)
87     return(False);              /* invalid screen */
88
89                                 /* now get the info from the XinerInfo */
90                                 /* struct and return it */
91
92   if (w != NULL)
93     *w = (DtXI->ScreenInfo[screen]).width;
94   if (h != NULL)
95     *h = (DtXI->ScreenInfo[screen]).height;
96   if (xorg != NULL)
97     *xorg = (DtXI->ScreenInfo[screen]).x_org;
98   if (yorg != NULL)
99     *yorg = (DtXI->ScreenInfo[screen]).y_org;
100
101   return(True);
102 }
103