banner

[Rule] Rules  [Home] Main Forum  [Portal] Portal  
[Members] Member Listing  [Statistics] Statistics  [Search] Search  [Reading Room] Reading Room 
[Register] Register  
[Login] Loginhttp  | https  ]
 
Forum Index Thảo luận hệ điều hành Windows getenv()  XML
  [Programming]   getenv() 18/09/2010 09:49:33 (+0700) | #1 | 220948
[Avatar]
panfider
Member

[Minus]    0    [Plus]
Joined: 12/05/2010 01:51:04
Messages: 448
Offline
[Profile] [PM] [Email]
hàm getenv() làm việc như thế nào ?
[Unix] live free or die
[Up] [Print Copy]
  [Programming]   getenv() 20/09/2010 08:53:11 (+0700) | #2 | 221070
mR.Bi
Member

[Minus]    0    [Plus]
Joined: 22/03/2006 13:17:49
Messages: 812
Offline
[Profile] [PM] [WWW]
http://www.unix.com/man-page/freebsd/3/getenv/
All of my life I have lived by a code and the code is simple: "honour your parent, love your woman and defend your children"
[Up] [Print Copy]
  [Programming]   getenv() 20/09/2010 20:06:22 (+0700) | #3 | 221144
[Avatar]
panfider
Member

[Minus]    0    [Plus]
Joined: 12/05/2010 01:51:04
Messages: 448
Offline
[Profile] [PM] [Email]
mình không nghĩ link trên giải thích đầy đủ
mình chỉ hiểu sơ sơ
nó nằm ở vùng nhớ chung nào đó mà ai truy suất cũng được,
nó được bash quản lý,
nhưng cơ chế quản lý như thế nào còn là mystery,
với lại bây giờ đang xài windows
[Unix] live free or die
[Up] [Print Copy]
  [Programming]   getenv() 20/09/2010 22:11:37 (+0700) | #4 | 221152
facialz
Elite Member

[Minus]    0    [Plus]
Joined: 20/07/2004 03:48:17
Messages: 197
Location: HoChiMinh city
Offline
[Profile] [PM]
Bác đang dùng Windows, hãy thử xuất ra vài giá trị này xem:

getenv("OS")

getenv("ComSpec")

getenv("windir")

[Up] [Print Copy]
  [Programming]   getenv() 20/09/2010 22:13:36 (+0700) | #5 | 221153
[Avatar]
Z0rr0
Q+WRtaW5pc3RyYXRvc+g

Joined: 14/08/2002 12:52:01
Messages: 1323
Location: Underground
Offline
[Profile] [PM] [WWW] [Yahoo!]
- Thế nào là Environment variables: http://en.wikipedia.org/wiki/Environment_variable
- getenv(): http://www.cplusplus.com/reference/clibrary/cstdlib/getenv/

Nếu đang dùng trên Windows thì chuyển câu hỏi này sang box Windows sẽ phù hợp hơn.
Hibernating
[Up] [Print Copy]
  [Programming]   getenv() 22/09/2010 20:39:10 (+0700) | #6 | 221252
[Avatar]
panfider
Member

[Minus]    0    [Plus]
Joined: 12/05/2010 01:51:04
Messages: 448
Offline
[Profile] [PM] [Email]
ok, minh tu tim hieu vay
cai nay hoi kho
[Unix] live free or die
[Up] [Print Copy]
  [Programming]   getenv() 22/09/2010 20:41:30 (+0700) | #7 | 221253
TQN
Elite Member

[Minus]    0    [Plus]
Joined: 29/06/2006 22:28:01
Messages: 888
Location: Biết làm chi ?
Offline
[Profile] [PM] [WWW] [Yahoo!]
getenv = Get enviroment variables. Coder C mà không tự tìm hiểu hàm đơn giản này được à ?

<stdlib.h>
getenv
char *getenv(const char *name);
The function searches an environment list, which each implementation defines, for an entry whose name matches the string name. If the function finds a match, it returns a pointer to a static-duration object that holds the definition associated with the target environment name. Otherwise, it returns a null pointer. Do not alter the value stored in the object. If you call getenv again, the value stored in the object can change. No target environment names are required of all environments.
 
[Up] [Print Copy]
  [Programming]   getenv() 23/09/2010 13:14:59 (+0700) | #8 | 221293
[Avatar]
panfider
Member

[Minus]    0    [Plus]
Joined: 12/05/2010 01:51:04
Messages: 448
Offline
[Profile] [PM] [Email]
trời xài thư viện chuẩn thì sao không xài được.
mình đang bàn luận hàm getenv làm việc như thế nào ?
[Unix] live free or die
[Up] [Print Copy]
  [Programming]   getenv() 24/09/2010 06:30:01 (+0700) | #9 | 221342
TQN
Elite Member

[Minus]    0    [Plus]
Joined: 29/06/2006 22:28:01
Messages: 888
Location: Biết làm chi ?
Offline
[Profile] [PM] [WWW] [Yahoo!]
Source cua Borland:

/*--------------------------------------------------------------------------*

Name getenv, _wgetenv - get string from environment

Usage char *getenv(const char *envvar);
whar_t *_wgetenv(const wchar_t *envvar);

Prototype in stdlib.h

Description The environment consists of a series of entries that
are of the form:

name=string\0

The global variable environ points to an array of pointers
to these entries. The last pointer in the array is NULL.
getenv searches the environment for the entry corresponding
to envvar, then returns a pointer to string.

The string comparison is NOT case-sensitive.

Return value On success, getenv and _wgetenv return a pointer to the value
associated with envvar.

*---------------------------------------------------------------------------*/

_TCHAR * _RTLENTRY _EXPFUNC _tgetenv_nolock(const _TCHAR *nameP)
{
#if defined(_UNICODE)
if (_ostype & _WINNT)
{
#endif
_TCHAR **envP;
int len;

len = _tcslen(nameP); /* save length of name */
if (len == 0)
return NULL;

for (envP = _tenviron; *envP != NULL; envP++)
if (_tcsnicmp(*envP,nameP,len) == 0 && (*envP)[len] == _TEXT('='))
break;

if (*envP)
return ((*envP)+len+1); /* point past the '=' */
else
return (NULL);
#if defined(_UNICODE)
}
else
return NULL;
#endif
}
 


May em khong co *nix nen khong co source
[Up] [Print Copy]
  [Programming]   getenv() 25/09/2010 07:51:57 (+0700) | #10 | 221426
[Avatar]
panfider
Member

[Minus]    0    [Plus]
Joined: 12/05/2010 01:51:04
Messages: 448
Offline
[Profile] [PM] [Email]
ok, thanks
mình sẽ reverse cái hàm này sớm thôi,
[Unix] live free or die
[Up] [Print Copy]
[digg] [delicious] [google] [yahoo] [technorati] [reddit] [stumbleupon]
Go to: 
 Users currently in here 
1 Anonymous

Powered by JForum - Extended by HVAOnline
 hvaonline.net  |  hvaforum.net  |  hvazone.net  |  hvanews.net  |  vnhacker.org
1999 - 2013 © v2012|0504|218|