1 /*
2  * Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /* clang-format off */
19 
20 /*	getdrivedirqq3f.c - Implements DFLIB getdrivedirqq subprogram.  */
21 
22 #include <string.h>
23 /* must include ent3f.h AFTER io3f.h */
24 #include "io3f.h"
25 #include "ent3f.h"
26 #include "utils3f.h"
27 #include "mpalloc.h"
28 
29 #if defined(WIN64) || defined(WIN32)
30 #define GETCWDM _getcwd /* getcwd deprecated in Windows in VC 2005 */
31 #else
32 #define GETCWDM getcwd
33 #endif
34 
35 extern char *GETCWDM();
36 extern char *__fstr2cstr();
37 
ENT3F(GETDRIVEDIRQQ,getdrivedirqq)38 int ENT3F(GETDRIVEDIRQQ, getdrivedirqq)(DCHAR(dir) DCLEN(dir))
39 {
40   char *p, *q;
41   int i, l1, l2;
42 
43   q = __fstr2cstr(CADR(dir), CLEN(dir));
44   l1 = CLEN(dir) + 1;
45   if (strlen(q) + 1 < l1)
46     l1 = strlen(q);
47   __cstr_free(q);
48   p = GETCWDM(NULL, l1);
49   if (p) {
50     __fcp_cstr(CADR(dir), CLEN(dir), p);
51     i = 0;
52     l2 = strlen(p);
53     if (l2 > CLEN(dir))
54       l2 = 0;
55     _mp_free(p);
56   } else {
57     i = __io_errno();
58     l2 = 0;
59   }
60 
61   return l2;
62 }
63