Ignore:
Timestamp:
01/29/13 16:22:48 (8 years ago)
Author:
davidb
Message:

Support for cross-compiling with Android-NDK added

Location:
main/trunk/greenstone2/common-src/src/getpw
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/src/getpw/Makefile.in

    r26679 r26798  
    6363endif
    6464
     65ifeq ($(GSDLOS),android)
     66  SOURCES += crypt.c crypt_util.c
     67endif
     68
    6569OBJECTS = \
    6670    getpw.o
     
    6973  # e.g. we are cross-compiling with mingw under Linux
    7074  OBJECTS += crypt.o crypt_util.o getpass.o
     75endif
     76
     77ifeq ($(GSDLOS),android)
     78  OBJECTS += crypt.o crypt_util.o
    7179endif
    7280
  • main/trunk/greenstone2/common-src/src/getpw/getpw.cpp

    r26649 r26798  
    120120#endif
    121121
     122
     123#if defined(__ANDROID__)
     124
     125// See:
     126//  http://stackoverflow.com/questions/1196418/getting-a-password-in-c-without-using-getpass-3
     127
     128#include <stdio.h>
     129#include <stdlib.h>
     130#include <termios.h>
     131
     132char* getpass(const char* prompt)
     133{
     134    struct termios oflags, nflags;
     135    char* password = (char*)malloc(64);
     136
     137    /* disabling echo */
     138    tcgetattr(fileno(stdin), &oflags);
     139    nflags = oflags;
     140    nflags.c_lflag &= ~ECHO;
     141    nflags.c_lflag |= ECHONL;
     142
     143    if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
     144        perror("tcsetattr");
     145        return NULL;
     146    }
     147
     148    printf(prompt);
     149    fgets(password, sizeof(password), stdin);
     150    password[strlen(password) - 1] = 0;
     151
     152    /* restore terminal */
     153    if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
     154        perror("tcsetattr");
     155        return NULL;
     156    }
     157
     158    return password;
     159}
     160#endif
     161
     162
     163
     164
    122165int main (int argc, char *argv[]) {
    123166
Note: See TracChangeset for help on using the changeset viewer.