The R Project SVN R

Rev

Rev 51815 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 51815 Rev 83775
Line 20... Line 20...
20
   WITHOUT ANY WARRANTY.
20
   WITHOUT ANY WARRANTY.
21
 
21
 
22
   See the file COPYLIB.TXT for details.
22
   See the file COPYLIB.TXT for details.
23
*/
23
*/
24
 
24
 
-
 
25
/* Copyright (C) 2023      The R Core Team
-
 
26
   Path length limitations
-
 
27
 */
-
 
28
 
25
#include "internal.h"
29
#include "internal.h"
26
 
30
 
27
/*
31
/*
28
 *  Windows implementation globals.
32
 *  Windows implementation globals.
29
 */
33
 */
Line 136... Line 140...
136
/*
140
/*
137
 *  Find out what the application is called.
141
 *  Find out what the application is called.
138
 */
142
 */
139
static void getappname(HANDLE Instance)
143
static void getappname(HANDLE Instance)
140
{
144
{
141
    char exename[MAX_PATH];
145
    char *exename = NULL;
142
    char title[MAX_PATH];
146
    char *title = NULL;
-
 
147
    DWORD rc;
143
 
148
 
144
    /* find out executable name */
149
    /* find out executable name */
-
 
150
 
-
 
151
    /* GetModuleFileName doesn't return the needed buffer size. */
-
 
152
    DWORD size = 1;
-
 
153
    for(;;) {
-
 
154
	exename = (char *)malloc(size);
-
 
155
	if (!exename)
-
 
156
            return;
145
    GetModuleFileName(Instance, exename, sizeof(exename));
157
        DWORD rc = GetModuleFileName(Instance, exename, size);
-
 
158
        if (rc > 0 && rc < size) /* success */
-
 
159
            break;
-
 
160
        free(exename);
-
 
161
        if (rc != size) /* error */
-
 
162
            return;
-
 
163
        size *= 2; /* try again with 2x larger buffer */
-
 
164
    }
-
 
165
 
-
 
166
    rc = GetFileTitle(exename, NULL, 0);
-
 
167
    if (!rc)
-
 
168
	return;
-
 
169
    title = (char *)malloc(rc);
-
 
170
    if (!title) {
-
 
171
	free(exename);
-
 
172
	return;
-
 
173
    }
146
    GetFileTitle(exename, title, sizeof(title));
174
    DWORD rc1 = GetFileTitle(exename, title, rc);
-
 
175
    free(exename);
-
 
176
    if (!rc1)
147
    setappname(title);
177
	setappname(title);
-
 
178
    free(title);
148
}
179
}
149
 
180
 
150
 
181
 
151
/*
182
/*
152
 *  The main Windows entry point is the WinMain function.
183
 *  The main Windows entry point is the WinMain function.