2 * Copyright (C) 2009 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * In wine you aren't allowed to compare file handles with 0,
20 * only with INVALID_HANDLE_VALUE.
32 * "(?:CreateFile|CreateMailslot|CreateNamedPipe|FindFirstFile(?:Ex)?|OpenConsole|SetupOpenInfFile|socket)[AW]?"
35 static const char *filehandle_funcs
[] = {
47 static void ok_to_use(struct sm_state
*sm
, struct expression
*mod_expr
)
49 if (sm
->state
!= &oktocheck
)
50 set_state(my_id
, sm
->name
, sm
->sym
, &oktocheck
);
53 static void match_returns_handle(const char *fn
, struct expression
*expr
,
56 char *left_name
= NULL
;
57 struct symbol
*left_sym
;
59 left_name
= expr_to_var_sym(expr
->left
, &left_sym
);
60 if (!left_name
|| !left_sym
)
62 set_state_expr(my_id
, expr
->left
, &filehandle
);
64 free_string(left_name
);
67 static void match_condition(struct expression
*expr
)
69 if (expr
->type
== EXPR_ASSIGNMENT
)
70 match_condition(expr
->left
);
72 if (get_state_expr(my_id
, expr
) == &filehandle
) {
75 name
= expr_to_var(expr
);
76 sm_msg("error: comparing a filehandle against zero '%s'", name
);
77 set_state_expr(my_id
, expr
, &oktocheck
);
82 void check_wine_filehandles(int id
)
86 if (option_project
!= PROJ_WINE
)
90 for (i
= 0; filehandle_funcs
[i
]; i
++) {
91 add_function_assign_hook(filehandle_funcs
[i
],
92 &match_returns_handle
, NULL
);
94 add_hook(&match_condition
, CONDITION_HOOK
);
95 add_modification_hook(my_id
, ok_to_use
);