Line 1... |
Line 1... |
1 |
/* This file is part of the SvarCOM project and is published under the terms
|
1 |
/* This file is part of the SvarCOM project and is published under the terms
|
2 |
* of the MIT license.
|
2 |
* of the MIT license.
|
3 |
*
|
3 |
*
|
4 |
* Copyright (C) 2021 Mateusz Viste
|
4 |
* Copyright (C) 2021-2022 Mateusz Viste
|
5 |
*
|
5 |
*
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
7 |
* copy of this software and associated documentation files (the "Software"),
|
7 |
* copy of this software and associated documentation files (the "Software"),
|
8 |
* to deal in the Software without restriction, including without limitation
|
8 |
* to deal in the Software without restriction, including without limitation
|
9 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
9 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
Line 68... |
Line 68... |
68 |
r++;
|
68 |
r++;
|
69 |
}
|
69 |
}
|
70 |
}
|
70 |
}
|
71 |
|
71 |
|
72 |
|
72 |
|
- |
|
73 |
/* locates the value of env variable varname and copies it to result, up to
|
- |
|
74 |
* ressz bytes (incl. the NULL terminator). returns the length of the value on
|
- |
|
75 |
* success, 0 if var not found or couldn't fit in ressz). */
|
- |
|
76 |
unsigned short env_lookup_valcopy(char *res, unsigned short ressz, unsigned short env_seg, const char *varname) {
|
- |
|
77 |
unsigned short i;
|
- |
|
78 |
char far *v = env_lookup_val(env_seg, varname);
|
- |
|
79 |
if (v == NULL) return(0);
|
- |
|
80 |
for (i = 0;; i++) {
|
- |
|
81 |
if (ressz-- == 0) return(0);
|
- |
|
82 |
res[i] = v[i];
|
- |
|
83 |
if (res[i] == 0) return(i);
|
- |
|
84 |
}
|
- |
|
85 |
}
|
- |
|
86 |
|
- |
|
87 |
|
73 |
/* returns the size, in bytes, of the allocated environment block */
|
88 |
/* returns the size, in bytes, of the allocated environment block */
|
74 |
unsigned short env_allocsz(unsigned short env_seg) {
|
89 |
unsigned short env_allocsz(unsigned short env_seg) {
|
75 |
unsigned short far *mcbsz = MK_FP(env_seg - 1, 3); /* block size is a word at offset +3 in the MCB */
|
90 |
unsigned short far *mcbsz = MK_FP(env_seg - 1, 3); /* block size is a word at offset +3 in the MCB */
|
76 |
return(*mcbsz * 16); /* return size in bytes, not paragraphs */
|
91 |
return(*mcbsz * 16); /* return size in bytes, not paragraphs */
|
77 |
}
|
92 |
}
|