@@ -40,106 +40,111 @@ void khrIcdOsVendorsEnumerate(void)
4040{
4141 DIR * dir = NULL ;
4242 struct dirent * dirEntry = NULL ;
43- char * vendorPath = khrIcd_secure_getenv ("OCL_ICD_VENDORS" );
44- if (vendorPath == NULL )
45- {
43+ char * vendorPath =
4644#ifdef __ANDROID__
47- vendorPath = "/system/vendor/Khronos/OpenCL/vendors/" ;
45+ "/system/vendor/Khronos/OpenCL/vendors/" ;
4846#else
49- vendorPath = "/etc/OpenCL/vendors/" ;
47+ "/etc/OpenCL/vendors/" ;
5048#endif // ANDROID
49+ char * envPath = NULL ;
50+
51+ khrIcdVendorsEnumerateEnv ();
52+
53+ envPath = khrIcd_secure_getenv ("OCL_ICD_VENDORS" );
54+ if (NULL != envPath )
55+ {
56+ vendorPath = envPath ;
5157 }
5258
53- // open the directory
5459 dir = opendir (vendorPath );
5560 if (NULL == dir )
5661 {
57- KHR_ICD_TRACE ("Failed to open path %s\n" , vendorPath );
58- goto Cleanup ;
62+ KHR_ICD_TRACE ("Failed to open path %s, continuing\n" , vendorPath );
5963 }
60-
61- // attempt to load all files in the directory
62- for (dirEntry = readdir (dir ); dirEntry ; dirEntry = readdir (dir ) )
64+ else
6365 {
64- switch (dirEntry -> d_type )
66+ // attempt to load all files in the directory
67+ for (dirEntry = readdir (dir ); dirEntry ; dirEntry = readdir (dir ) )
6568 {
66- case DT_UNKNOWN :
67- case DT_REG :
68- case DT_LNK :
69+ switch (dirEntry -> d_type )
6970 {
70- const char * extension = ".icd" ;
71- FILE * fin = NULL ;
72- char * fileName = NULL ;
73- char * buffer = NULL ;
74- long bufferSize = 0 ;
75-
76- // make sure the file name ends in .icd
77- if (strlen (extension ) > strlen (dirEntry -> d_name ) )
78- {
79- break ;
80- }
81- if (strcmp (dirEntry -> d_name + strlen (dirEntry -> d_name ) - strlen (extension ), extension ) )
82- {
83- break ;
84- }
85-
86- // allocate space for the full path of the vendor library name
87- fileName = malloc (strlen (dirEntry -> d_name ) + strlen (vendorPath ) + 1 );
88- if (!fileName )
71+ case DT_UNKNOWN :
72+ case DT_REG :
73+ case DT_LNK :
8974 {
90- KHR_ICD_TRACE ("Failed allocate space for ICD file path\n" );
91- break ;
92- }
93- sprintf (fileName , "%s%s" , vendorPath , dirEntry -> d_name );
75+ const char * extension = ".icd" ;
76+ FILE * fin = NULL ;
77+ char * fileName = NULL ;
78+ char * buffer = NULL ;
79+ long bufferSize = 0 ;
80+
81+ // make sure the file name ends in .icd
82+ if (strlen (extension ) > strlen (dirEntry -> d_name ) )
83+ {
84+ break ;
85+ }
86+ if (strcmp (dirEntry -> d_name + strlen (dirEntry -> d_name ) - strlen (extension ), extension ) )
87+ {
88+ break ;
89+ }
90+
91+ // allocate space for the full path of the vendor library name
92+ fileName = malloc (strlen (dirEntry -> d_name ) + strlen (vendorPath ) + 1 );
93+ if (!fileName )
94+ {
95+ KHR_ICD_TRACE ("Failed allocate space for ICD file path\n" );
96+ break ;
97+ }
98+ sprintf (fileName , "%s%s" , vendorPath , dirEntry -> d_name );
99+
100+ // open the file and read its contents
101+ fin = fopen (fileName , "r" );
102+ if (!fin )
103+ {
104+ free (fileName );
105+ break ;
106+ }
107+ fseek (fin , 0 , SEEK_END );
108+ bufferSize = ftell (fin );
109+
110+ buffer = malloc (bufferSize + 1 );
111+ if (!buffer )
112+ {
113+ free (fileName );
114+ fclose (fin );
115+ break ;
116+ }
117+ memset (buffer , 0 , bufferSize + 1 );
118+ fseek (fin , 0 , SEEK_SET );
119+ if (bufferSize != (long )fread (buffer , 1 , bufferSize , fin ) )
120+ {
121+ free (fileName );
122+ free (buffer );
123+ fclose (fin );
124+ break ;
125+ }
126+ // ignore a newline at the end of the file
127+ if (buffer [bufferSize - 1 ] == '\n' ) buffer [bufferSize - 1 ] = '\0' ;
128+
129+ // load the string read from the file
130+ khrIcdVendorAdd (buffer );
94131
95- // open the file and read its contents
96- fin = fopen (fileName , "r" );
97- if (!fin )
98- {
99- free (fileName );
100- break ;
101- }
102- fseek (fin , 0 , SEEK_END );
103- bufferSize = ftell (fin );
104-
105- buffer = malloc (bufferSize + 1 );
106- if (!buffer )
107- {
108- free (fileName );
109- fclose (fin );
110- break ;
111- }
112- memset (buffer , 0 , bufferSize + 1 );
113- fseek (fin , 0 , SEEK_SET );
114- if (bufferSize != (long )fread (buffer , 1 , bufferSize , fin ) )
115- {
116132 free (fileName );
117133 free (buffer );
118134 fclose (fin );
119- break ;
120135 }
121- // ignore a newline at the end of the file
122- if (buffer [bufferSize - 1 ] == '\n' ) buffer [bufferSize - 1 ] = '\0' ;
123-
124- // load the string read from the file
125- khrIcdVendorAdd (buffer );
126-
127- free (fileName );
128- free (buffer );
129- fclose (fin );
136+ break ;
137+ default :
138+ break ;
130139 }
131- break ;
132- default :
133- break ;
134140 }
135- }
136141
137- Cleanup :
142+ closedir (dir );
143+ }
138144
139- // free resources and exit
140- if (dir )
145+ if (NULL != envPath )
141146 {
142- closedir ( dir );
147+ khrIcd_free_getenv ( envPath );
143148 }
144149}
145150
0 commit comments